简体   繁体   English

在这种情况下如何编写嵌套查询?

[英]how to write nested query for this scenario?

cars_aircraft table cars_aircraft表

id, aircraft_name, home_base_address,alternate_base_airport 

1 ,     MIG 20   ,         77   ,               80

2   ,   MIG 30   ,         80       ,50           

cars_airport table cars_机场表

id ,airport_city , airport_name

1    ,  mumbai      ,    CST

2   , pune       ,    PIA

i need aircraft_name,airport_name as a result for airport_city="mumbai". 由于需要使用airport_city =“ mumbai”,因此需要我的飞机名,机场名

Condition is that in search not only searched city's aircraft will come as well as neighour city's aircraft should also come. 条件是搜索不仅要搜索城市的飞机,邻居城市的飞机也要来。

ie neighour city of mumbai is pune(based on alternative_base_airport value of mumbai which is home_base_address of pune , so for mumbai search mumbai and pune both should come) 即,孟买的邻居城市是浦那(基于孟买的Alternative_base_airport值,即浦那的home_base_address,因此对于孟买来说,搜索孟买和浦那都应该来)

please help 请帮忙

The second table doesn't look like it's got any association with the first... but this is something you can do: 第二张表看起来与第一张表没有任何关联...但这是您可以执行的操作:

Select * from table where airport="Mumbai" union select * from table where home_base in (select alternative_base from table where homebase = "Mumbai") 从“ airport =“ Mumbai”联合体的表中选择*从home_base所在的表中选择*(从homebase =“孟买”的表中选择*)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM