我正试图让座位更多的航班没有。我在MySQL中有3个表
1. Sector
2. Flights
3. Aircraft
请按1,2和3的顺序查看表格结构的图像
我正在写这个SQL
select * from aircraft
where aircrafttypeID=
(select aircrafttypeID
from sector,flights
where source like 'Kolkata'
and destination like 'Ahmedabad'
and sector.sectorID=flights.sectorID)
and bseats>0
此查询提供错误 -
子查询返回超过1行
因为子查询重新调整了多个航班号。所以我需要一些帮助,如何获得座位超过0的航班号
答案 0 :(得分:3)
试试这个
SELECT *
FROM aircraft
WHERE aircrafttypeID IN ( SELECT aircrafttypeID
FROM sector ,
flights
WHERE source LIKE 'Kolkata'
AND destination LIKE 'Ahmedabad'
AND sector.sectorID = flights.sectorID
)
AND bseats > 0
答案 1 :(得分:2)
只是一个建议。您可以在子查询上使用join。
select *
from aircraft a
inner join flights f
on a.aircrafttypeID=f.aircrafttypeID
inner join source s
on s.sectorID=f.sectorID
and s.source LIKE 'Kolkata'
and s.destination LIKE 'Ahmedabad'
and a.bseats>0