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

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

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

# 1、关键是把每月新增的用户数求出来,先把每个用户的最早出现时间找出来,再根据这个时间分组看每月有几个新增
# 2、再用开窗函数把后面两个指标查出,接着关联每月的客户数即可
# 3、注意用左连接,因为某月新增的可能为0,判断下没关联上的就是0,表示这个月么有新增
select t1.start_month,t1.mau,coalesce(t2.month_add_uv,0) as month_add_uv,
       max(t2.month_add_uv)over(order by t1.start_month) as max_month_add_uv,
       sum(t2.month_add_uv)over(order by t1.start_month) as cum_sum_uv
from (
    select date_format(start_time,'%Y%m') as start_month,count(distinct uid) as mau
    from exam_record
    group by date_format(start_time,'%Y%m')
    )t1
left join (
            select min_start_month as start_month,count(1) as month_add_uv
            from (
                select uid,min(date_format(start_time,'%Y%m')) as min_start_month
                from exam_record
                group by uid
                ) t
            group by min_start_month
           ) t2
on t1.start_month = t2.start_month
order by t1.start_month
            



全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
弦五Strings:他之所以会举报你代课是因为在这种人眼里正常上课就是正义代课就是邪恶,典型二极管思维,处理方法就是私下沟通,你就说你自己家里经济困难或者家里父母生病什么之类的,需要去打工挣钱,用尽孝的正义对冲他认为的上课的正义,他可能就妥协了。
我的实习日记
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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