有一个登录(login)记录表,简况如下:
1、每个日期登录新用户个数
2、结果按照日期升序排序
上面的例子查询结果如下:
首先求出新登录的用户登录的日期
select user_id, min(date) from login group by user_id
然后统计出每个日期的人数
select date, (sum(case when (user_id, date) in (select user_id, min(date) from login group by user_id) then 1 else 0 end)) as new from login group by date order by date;