Last active
October 18, 2020 15:36
-
-
Save sjtalkar/c50d51c8d46bd7d72170a9b612d3e906 to your computer and use it in GitHub Desktop.
Analytical function window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with cf as (select | |
unique_carrier, | |
origin_city, | |
origin_state, | |
destination_city_name, | |
destination_state, | |
sum (case when arrival_delay > 0 then 1 else 0 end) as count_delayed_flights, | |
count(arrival_delay) as total_flight_count | |
from "ArrivalInfo" | |
group by | |
unique_carrier, | |
origin_city, | |
origin_state, | |
destination_city_name, | |
destination_state), | |
df as (select | |
unique_carrier, | |
origin_city, | |
origin_state, | |
destination_city_name, | |
destination_state, | |
count_delayed_flights, | |
sum (count_delayed_flights) | |
over (partition by origin_city, origin_state, destination_city_name, destination_state) as delayed_per_origin, | |
total_flight_count | |
from cf) | |
select * from df; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment