Skip to content

Instantly share code, notes, and snippets.

@mikebuchanon
Created July 6, 2012 16:30
Show Gist options
  • Save mikebuchanon/3061191 to your computer and use it in GitHub Desktop.
Save mikebuchanon/3061191 to your computer and use it in GitHub Desktop.
Average logins per hour by day of week
with user_stats as (
select extract(dow from to_timestamp(time)) as day_of_week,
extract(hour from to_timestamp(time)) as hour_of_day,
count(1) as logins
from mdl_log
where action='login'
and to_timestamp(time) > '6/30/2012'
group by extract(dow from to_timestamp(time)), extract(hour from to_timestamp(time))
)
select day_of_week, hour_of_day, avg(logins) as avg_logins
from user_stats
group by day_of_week, hour_of_day
order by day_of_week, hour_of_day;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment