24 - 查询近30天活跃用户数
- 排序和分组
-- 日期相减 date_sub('2019-07-27', interval 30 day)获取新的日期
-- 日期范围 datediff('2019-07-27',activity_date)<30
-- where activity_date > date_sub('2019-07-27', interval 30 day)
-- and activity_date <= '2019-07-27'=where datediff('2019-07-27',activity_date)<30
select
activity_date day,count(distinct user_id) active_users
from
Activity
where
datediff('2019-07-27',activity_date)<30
GROUP BY
activity_date;