Skip to content

Instantly share code, notes, and snippets.

@steverobbins
Last active July 29, 2017 16:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save steverobbins/bffcb136a65c9f1b32d5 to your computer and use it in GitHub Desktop.
Save steverobbins/bffcb136a65c9f1b32d5 to your computer and use it in GitHub Desktop.
select
`Time Period`,
round(avg(num), 1) `Average Number of Orders`
from (
select
date_format(date_sub(o.created_at, interval 8 hour), "%l:00 - %l:59 %p PST") `Time Period`,
count(*) num,
date_format(date_sub(o.created_at, interval 8 hour), "%H") sort
from sales_flat_order o
where o.created_at > '2016-01-01 00:00:00'
and o.created_at < '2016-02-01 00:00:00'
group by date_format(date_sub(o.created_at, interval 8 hour), "%Y-%m-%d-%H")
) t
group by `Time Period`
order by sort;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment