Created
February 5, 2023 18:03
-
-
Save nuria/1c85b22eae99fcc31b297fa77f6c3658 to your computer and use it in GitHub Desktop.
avg and sum as window functions
This file contains 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 base_data as ( | |
-- | |
select date_trunc('day', received_at) as received_at, count(*) as events_received | |
from some_com.performance_largest_contentful_paint where received_at > '2022-01-01' | |
group by date_trunc('day', received_at) order by date_trunc('day', received_at) | |
) | |
select received_at, events_received , | |
avg(events_received) over (partition by date_trunc('month',received_at)) as monthly_avg , | |
max(events_received) over (partition by date_trunc('month', received_at)) as monthly_max | |
from base_data order by received_at |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment