【发布时间】:2017-05-01 06:43:09
【问题描述】:
我有一个返回以下内容的查询。
select
trunc(t.created),
sum(count(*)) over (order by trunc(t.created) rows unbounded preceding) as cumulative_sales
from event e
LEFT JOIN person_tickets t on e.id = t.event_id
where event_id = 9999
group by trunc(t.created)
Date cumulative_bookings
2016-02-12 1
2016-02-18 3
2016-02-19 5
2016-02-20 352
2016-02-21 352
我想填写日期系列,以便包含所有日期。
2016-02-12 1
2016-02-13 1
2016-02-14 1
2016-02-15 1
2016-02-16 1
2016-02-17 1
2016-02-18 3
2016-02-19 5
2016-02-20 352
2016-02-21 352
我一直在尝试加入为我生成一个不错的日期序列的代码,但我很难了解在哪里或如何优雅地进行加入。
select (
getdate()::date - row_number() over (order by true)
)::date as n
from event limit 500
在以下方面取得了一些进展,但并不完全在那里
CASE WHEN cumulative_bookings is null then LAG(cumulative_bookings IGNORE NULLS) OVER (ORDER BY n)
ELSE cumulative_bookings END as filled_cumulative_bookings
【问题讨论】:
标签: sql date amazon-redshift