我有一张表格,显示每个日期的客户ID列表 - 显示在特定日期活跃的客户。所以每个日期都可以包含也存在于另一个日期的id。按日期累计计数问题
bdate customer_id
2012-01-12 111
2012-01-13 222
2012-01-13 333
2012-01-14 111
2012-01-14 333
2012-01-14 666
2012-01-14 777
我期待写一个计算的唯一ID的两个日期之间的总数查询 - 起始日期是行日期和结束日期在未来的某个特定日期。
我的查询看起来是这样的:
select
bdate,
count(distinct customer_id) as cts
from users
where bdate between bdate and current_date
group by 1
order by 1
但是,这会产生独特的用户的数量对于每一日期,就像这样:
bdate customer_id
2012-01-12 1
2012-01-13 2
2012-01-14 4
我期望的结果是(为起点之间的用户的数量排日期和2012-01-14)
bdate customer_id
2012-01-12 5 - includes (111,222,333,666,777)
2012-01-13 5 - includes (222,333,111,666,777)
2012-01-14 4 - includes (111,333,666,777)
看看你能不能让你一个加入工作 – Strawberry
你能详细点吗? – user2022284