forked from HONGWENRU/flightreservation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_flight.sql
More file actions
74 lines (63 loc) · 2.58 KB
/
query_flight.sql
File metadata and controls
74 lines (63 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* table info of all flight instance*/
select *
from flightinstance fin join flights f using(fid)
join flightfares fare using(fid)
join airlines using(alid);
/* select avilable flight from cannada to us*/
select t1.fid,t1.fdate,t1.alid,t1.start_apid,t1.end_apid
from (select *
from flightinstance fin join flights f using(fid)
join flightfares fare using(fid)
join airlines line using(alid)) t1,
airport port1, airport port2
where t1.start_apid=port1.apid and port1.country='Canada'
and t1.end_apid=port2.apid and port2.country='United States';
/* select avilable flight from BCN to SDR*/
select t1.fid,t1.fdate,t1.alid,t1.start_apid,port1.IATA,t1.end_apid,port2.IATA
from (select *
from flightinstance fin join flights f using(fid)
join flightfares fare using(fid)
join airlines line using(alid)) t1,
airport port1, airport port2
where t1.start_apid=port1.apid and port1.IATA='BCN'
and t1.end_apid=port2.apid and port2.IATA='SDR';
/* ROUND TRIP select avilable flight from BCN to SDR*/
select t1.fid,t1.fdate,t1.alid,t1.start_apid,port1.IATA,t1.end_apid,port2.IATA
from (select *
from flightinstance fin join flights f using(fid)
join flightfares fare using(fid)
join airlines line using(alid)) t1,
airport port1, airport port2
where t1.start_apid=port1.apid and port1.IATA='BCN'
and t1.end_apid=port2.apid and port2.IATA='SDR'
and t1.fdate between '2000-12-31' and '2014-12-31'+interval 5 year
union
select t2.fid,t2.fdate,t2.alid,t2.start_apid,port3.IATA,t2.end_apid,port4.IATA
from (select *
from flightinstance fin join flights f using(fid)
join flightfares fare using(fid)
join airlines line using(alid)) t2,
airport port3, airport port4
where t2.start_apid=port3.apid and port3.IATA='SDR'
and t2.end_apid=port4.apid and port4.IATA='BCN'
and t2.fdate between '2014-12-31' and '2014-12-31'+interval 5 year;
/* select all reservation that reserve flight during 2014 */
select *
from reservation r
join reservetaking rt using(r_num)
join flightinstance fin using(fid,fdate)
join flights fl using(fid)
join airlines al using(alid)
where fdate between '2013-12-31' and '2015-01-01'
and rstate='success';
/* select sum of reservation of each airline that reserve flight during 2014 */
select t1.alid,t1.airline_name,count(*)
from (select *
from reservation r
join reservetaking rt using(r_num)
join flightinstance fin using(fid,fdate)
join flights fl using(fid)
join airlines al using(alid)
where fdate between '2013-12-31' and '2015-01-01'
and rstate='success') t1
group by t1.alid;