Last active
August 29, 2015 14:20
-
-
Save chanmix51/11bf1dd4820ad1828318 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
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