我有以下任务:SQL创建视图连接航班
我需要创建一个视图,显示第1次航班和他的连接航班。
在这个例子中FlightNo 1 & 2.
-
我的飞行表:
FlightNo---Date--------StartTime---ArrivingTime---StartPort---DestinationPort
1. ----2014-11-20---01:00:55-----02:00:34----------a----------------b
2. ----2014-11-20---02:10:55-----03:00:34----------b----------------c
3. ----2014-11-20---20:00:55-----21:00:34----------x----------------q
4. ----2014-11-20---00:00:55-----01:00:34----------a----------------u
...
到目前为止我的代码:
create OR REPLACE view FlightConnection as
select* FROM Flight a
where exists (select* FROM Flight b
where a.StartPort = b.DestinationPort and
a.ArrivingTime < b.StartTimet);
我的输出:
FlightNo---Date--------StartTime---ArrivingTime---StartPort---DestinationPort
---1 ----2014-11-20---01:00:55-----02:00:34----------a----------------b
-
但我需要FlightNo 1和2 我尝试了几种不同的事情,但我想我暂时哑。
请帮忙。 (对不起,我的英语)
所以,你要对航班,使得第一的目的端口是第二的起始端口,和第一的到达时间是第二次的起飞时间前? – 2014-11-21 18:32:27