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

select
    *,
    max(month_add_uv) over (
        order by
            start_month
    ) max_month_add_uv,
    sum(month_add_uv) over (
        order by
            start_month
    ) cum_sum_uv
from
    (
        select
            start_month,
            count(distinct uid) mau,
            sum(判断是否为新增用户) month_add_uv
        from
            (
                select
                    *,
                    date_format (start_time, '%Y%m') start_month,
                    if (
                        min(start_time) over (
                            partition by
                                uid
                            order by
                                start_time
                        ) = start_time,
                        1,
                        0
                    ) 判断是否为新增用户
                from
                    test.exam_record
            ) a
        group by
            start_month
    ) b

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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