2表,一个有航班,一个有目的地。 我希望所有出发和到达的航班都在表2中(为我工作)。但是我希望到达后离开。见例子 谢谢大家
CREATE TABLE flights
(`Name` varchar(10), `Departure` varchar(50), `Arrival` varchar(10), `Pass` int, `Cargo` int, `Dist` int)
;
INSERT INTO flights
(`Name`, `Departure`, `Arrival`, `Pass`, `Cargo`, `Dist`)
VALUES
('444 737vvv', 'LFLL gee', 'LPMAdsf', 200, 2000, 12),
('gg737vvv', 'LPMA-egege', 'LFLLdsf', 3000, 0, 13),
('747vvv', 'LFLLèèegege', 'LPMAdsf', 0, 5000, 15),
('747vvv', 'OTHHèèegege', 'LPMAdsf', 0, 5000, 15),
('747vvv', 'OMDBèèegege', 'LPMAdsf', 0, 5000, 15),
('a320vvv', 'EGKK-egege', 'LFPOdd', 0, 6000, 14)
;
CREATE TABLE Regular
(`Dep` varchar(21), `Arri` varchar(21),`Type` varchar(21))
;
INSERT INTO Regular
(`Dep`, `Arri`, `type`)
VALUES
('LFLL', 'LFPG', 'cargo'),
('LFPG', 'LFLL', 'cargo'),
('LFLL', 'LPMA', 'com'),
('LPMA', 'LFLL', 'cargo'),
('LFPO', 'EGKK', 'cargo'),
('EGKK', 'LFPO', 'com')
;
根据这个要求,我有所有航班,其中Departure et Arrival在常规表中。好!但我希望只有到达后离开的航班。
今天以此为例:
$query = "Select
flights.UserName,
flights.FlightDate,
flights.FlightResult,
flights.AircraftName,
flights.DepartureIcaoName,
flights.ArrivalIcaoName
from
flights
inner join regular
on regular.Departure = SUBSTRING(flights.DepartureIcaoName,1,4) and regular.Arrival = SUBSTRING(flights.ArrivalIcaoName,1,4);";
我有:
('444 737vvv', 'LFLL gee', 'LPMAdsf', 200, 2000, 12),
('gg737vvv', 'LPMA-egege', 'LFLLdsf', 3000, 0, 13),
('747vvv', 'LFLLèèegege', 'LPMAdsf', 0, 5000, 15),
('a320vvv', 'EGKK-egege', 'LFPOdd', 0, 6000, 14)
我想:
('444 737vvv', 'LFLL gee', 'LPMAdsf', 200, 2000, 12),
('gg737vvv', 'LPMA-egege', 'LFLLdsf', 3000, 0, 13),
('747vvv', 'LFLLèèegege', 'LPMAdsf', 0, 5000, 15),
我认为(但不行):
$query = "Select
flights.*, regular.*
from flights, regular
where regular.Departure = SUBSTRING(flights.DepartureIcaoName,1,4)
and regular.Arrival = SUBSTRING(flights.ArrivalIcaoName,1,4)
and SUBSTRING(flights.DepartureIcaoName,1,4) = (SUBSTRING(flights.ArrivalIcaoName,1,4) - 1)
";