查询旅行社项目

时间:2014-12-16 17:09:27

标签: mysql join

我需要打印所有从(例如ABC)出发的航班的航班号和出发/到达时间,并于2012年3月3日到达(例如XYZ)机场。

航班表:

flight_number(primary key),
airline_name(foreign key), 
weekdays,
departure_airport,
arrival_airport,
departure_time,
arrival_time, 
no_of_seats)

机场表:

airport_code(primary key),
airport_name,
airline_name(foreign key),
address_state,
address_city,
address_telno

我使用子查询完成了此操作,但需要使用 JOINS 来完成此操作。 这是我使用的子查询

select flight_number,departure_time,arrival_time 
from (
    select * from flight
    where(flight.departure_airport='ABC' AND flight.arrival_airport='XYZ')
);

我尝试过使用以下查询:

select flight_number,weekdays,departure_airport,arrival_airport,departure_time,arrival_‌​time,no_of_seats 
FROM (SELECT * FROM flight 
INNER JOIN airport ON flight.departure_airport = airport.airport_code 
WHERE (airport.airport_code = '08' OR airport.address_city='RUH')) ;

我收到错误:invalid number at line 4 –

1 个答案:

答案 0 :(得分:0)

试试这个:

select flight_number, departure_time 
from flight left join Airport on fligt.airline_name = Airport.airline_name 
where date(departure_time) = '2012-03-03' and airport_name = 'your_airport_name' 
and departure_airport = 'your_dept_port' and 
arrival_airport = 'your_arrival_port'