Skip to content

Instantly share code, notes, and snippets.

@chanmix51
Last active August 29, 2015 14:20
Show Gist options
  • Save chanmix51/11bf1dd4820ad1828318 to your computer and use it in GitHub Desktop.
Save chanmix51/11bf1dd4820ad1828318 to your computer and use it in GitHub Desktop.
--
select
sale.seller_id,
wd.day_date::date as day,
count(sale.sale_id) as sales,
coalesce(sum(sale.total_price_ct)/100, 0) as total
from
(select generate_series('2015-04-13', '2015-04-20', '1 day'::interval) as day_date) wd
left join sale on sale.seller_id = 3 and wd.day_date = date_trunc('day', sale_ts)
group by 1,2
order by day asc
;
--
select
seller.name,
wd.day_date::date as day,
count(sale.sale_id) as sales,
coalesce(sum(sale.total_price_ct)/100, 0) as total
from
seller
cross join (select generate_series('2015-04-13', '2015-04-20', '1 day'::interval) as day_date) wd
left join sale on sale.seller_id = seller.seller_id and wd.day_date = date_trunc('day', sale_ts)
group by 1,2
order by day asc
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment