Skip to content

Instantly share code, notes, and snippets.

Created February 5, 2023 18:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
avg and sum as window functions
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