Skip to content

Instantly share code, notes, and snippets.

@JoseSoteloCohen
Last active June 25, 2021 06:15
Show Gist options
  • Save JoseSoteloCohen/96f897cd0b43881b3a090e9b68172bbb to your computer and use it in GitHub Desktop.
Save JoseSoteloCohen/96f897cd0b43881b3a090e9b68172bbb to your computer and use it in GitHub Desktop.
with _data as (
select
date_trunc('week', orders.completed_at) as week, --tried to change to EST with convert_timezone('EST', completed_at) but didn't work
sum(orders.order_total) as sales_total,
users.signup_channel as signup_channel,
orders.order_category as order_category,
concat(concat(signup_channel, ' - '), order_category) as series --didn't understand how to use as a series
from orders
join users
on users.user_id = orders.user_id
where completed_at between '2019-10-01' and '2019-12-31'
group by week, signup_channel, order_category, series
)
select
week,
signup_channel,
order_category,
sum(sales_total) over (order by week asc rows unbounded preceding) as Total_Running_Sales
from _data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment