# 使用窗口函数来添加一列初始登录日期
select *, min(`date`)over(partition by user_id) f
from login
# 筛选出登录记录表中各用户在其第一次登录日期的登录记录,并注意去重(某用户在初始登录日期多次登录情况)
select `date`, count(distinct (case f when `date` then user_id else null end)) new
from (
select *, min(`date`)over(partition by user_id) f
from login
) k1
group by `date`
order by `date`;



京公网安备 11010502036488号