-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path5.sql
More file actions
31 lines (30 loc) · 780 Bytes
/
5.sql
File metadata and controls
31 lines (30 loc) · 780 Bytes
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
-- Query 5: California airport flight volumes and delays by airline
-- Analyzes flight volumes and average arrival delays for flights arriving at California airports
-- in 2020, demonstrating star schema joins between flights, airlines, and airports
WITH california_flights AS (
SELECT
a.airline,
ap.airport,
COUNT(*) AS volume,
AVG(f.arr_delay) AS avg_arrival_delay
FROM
flights f
JOIN
airlines a ON f.carrier = a.iata_code
JOIN
airports ap ON f.dest = ap.iata_code
WHERE
ap.state = 'CA'
AND f.year = 2020
GROUP BY
a.airline, ap.airport
)
SELECT
airline,
airport,
volume,
avg_arrival_delay
FROM
california_flights
ORDER BY
airline, airport;