-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairline_queries.sql
60 lines (56 loc) · 1.47 KB
/
airline_queries.sql
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
use flights_delays;
## Query 1
SELECT origin_airport, COUNT(*) AS total_delays
FROM flights
WHERE DEPARTURE_DELAY > 0
GROUP BY origin_airport
ORDER BY total_delays DESC
LIMIT 10;
## Query 2
SELECT 'Air System Delay' AS delay_type,
SUM(AIR_SYSTEM_DELAY) AS total_delay
FROM flights
UNION ALL
SELECT
'Security Delay' AS delay_type,
SUM(SECURITY_DELAY) AS total_delay
FROM flights
UNION ALL
SELECT
'Airline Delay' AS delay_type,
SUM(AIRLINE_DELAY) AS total_delay
FROM flights
UNION ALL
SELECT
'Late Aircraft Delay' AS delay_type,
SUM(LATE_AIRCRAFT_DELAY) AS total_delay
FROM flights
UNION ALL
SELECT
'Weather Delay' AS delay_type,
SUM(WEATHER_DELAY) AS total_delay
FROM flights
ORDER BY total_delay DESC;
## Query 3
SELECT a.AIRLINE,
SUM(f.AIR_SYSTEM_DELAY) AS air_system_delay,
SUM(f.SECURITY_DELAY) AS security_delay,
SUM(f.AIRLINE_DELAY) AS airline_delay,
SUM(f.LATE_AIRCRAFT_DELAY) As late_aircraft_delay,
SUM(f.WEATHER_DELAY) AS weather_delay
FROM flights f
JOIN airline a ON fAIRLINE = a.IATA_CODE
GROUP BY f.AIRLINE, a.AIRLINE
ORDER BY airline_delay DESC, air_system_delay DESC, security_delay;
## Query 4
SELECT origin_airport,
SUM(AIR_SYSTEM_DELAY) AS air_system_delay,
SUM(SECURITY_DELAY) AS security_delay,
SUM(AIRLINE_DELAY) AS airline_delay,
SUM(LATE_AIRCRAFT_DELAY) AS late_aircraft_delay,
SUM(WEATHER_DELAY) AS weather_delay
FROM flights
WHERE DEPARTURE_DELAY > 0
GROUP BY origin_airport
ORDER BY airline_delay DESC, air_system_delay DESC, security_delay
LIMIT 10;