0
我有一个查询返回以下内容。在Redshift上填写日期范围
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