蜂巢/帕拉变化表计数

问题描述 投票:0回答:1

我有发布日期的列表(一些过去和将来)和注册号码清单。

release date     registration
01/01/2019        R1
02/01/2019        R2
07/02/2019        R3

我基本上要创建一个新表将显示注册号总数为每一天(将来的日期)。

date            total registration numbers
05/02/2019       2
06/02/2019       2
07/02/2019       3

我知道如何使用count(*)找到登记数目,我已经想过这个带有日历表合并为将来的日期。

sql hive impala
1个回答
0
投票

如果你有一个日历表,你可以使用窗口函数:

select c.date,
       count(t.date) as registrations_on_day,
       sum(count(t.date)) over (order by c.date) as registrations_through_day
from calendar c left join
     t
     on c.date = t.date
group by c.date
order by c.date;
© www.soinside.com 2019 - 2024. All rights reserved.