假设我有我的table
喜欢:
uid day_used_app
--- -------------
1 2012-04-28
1 2012-04-29
1 2012-04-30
2 2012-04-29
2 2012-04-30
2 2012-05-01
2 2012-05-21
2 2012-05-22
2012-05-03
假设我想要在过去 7 天(从)中至少 2 天返回应用的唯一用户数。
例如,检索过去 7 天内至少 2 天使用过该应用程序的用户数:
select count(distinct case when num_different_days_on_app >= 2
then uid else null end) as users_return_2_or_more_days
from (
select uid,
count(distinct day_used_app) as num_different_days_on_app
from table
where day_used_app between current_date() - 7 and current_date()
group by 1
)
这给了我:
users_return_2_or_more_days
---------------------------
2
我的问题是:
如果我想到目前为止的每一天都这样做,我的表看起来像这样,其中第二个字段等于在第一个字段中的日期之前一周内返回 2 个或更多不同天的唯一用户数。
date users_return_2_or_more_days
-------- ---------------------------
2012-04-28 2
2012-04-29 2
2012-04-30 3
2012-05-01 4
2012-05-02 4
2012-05-03 3