【发布时间】:2019-04-22 17:36:59
【问题描述】:
一周内活跃 # 天的分布:我试图找出在 3 月 1 日至 3 月 7 日的特定周内 1 天、2 天、3 天、…7 天活跃的成员数量。
有什么方法可以在分区之上使用聚合函数吗? 如果不是,可以用什么来实现这一点?
select distinct memberID,count(date) over(partition by memberID) as no_of_days_active
from visitor
where date between '"2019-01-01 00:00:00"' and '"2019-01-07 00:00:00"'
order by no_of_days_active
结果应该是这样的
#Days Active Count
1 20
2 32
3 678
4 34
5 3
6 678
7 2345
【问题讨论】:
标签: sql postgresql windowing partition-by