题解 | 每月及截止当月的答题情况

每月及截止当月的答题情况

https://www.nowcoder.com/practice/1ce93d5cec5c4243930fc5e8efaaca1e

select 
    start_month,
    mau,
    ifnull(month_add_uv,0),
    max(month_add_uv) over(rows between unbounded preceding and current row) as max_month_add_uv,
    sum(month_add_uv) over(rows between unbounded preceding and current row) as cum_sum_uv
from
(
    select
    date_format(start_time, '%Y%m') as start_month,
    count(distinct uid) as mau
from exam_record er
group by start_month
)t1
left join 
(
    select 
    com_time,
    count(uid) as month_add_uv
    from
    (
        select
        uid,
        min(date_format(start_time, '%Y%m')) as com_time
        from exam_record er 
        group by uid
    ) t
    group by com_time
)t2
on t1.start_month = t2.com_time

全部评论

相关推荐

牛客nb666号:见天才的门槛罢了查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务