题解 | 月均完成试卷数不小于3的用户爱作答的类别

月均完成试卷数不小于3的用户爱作答的类别

https://www.nowcoder.com/practice/b1d13efcfa0c4ecea517afbdb9090845

select
    tag, count(uid) as tag_cnt
from
    examination_info i
    inner join exam_record r using (exam_id)
where
    uid in (
        select
            uid
        from
            exam_record
        where
            date_format (start_time, '%Y%m') = date_format (submit_time, '%Y%m')
            and submit_time is not null
        # 这里要按照month分一次组,否则一个用户1月作答次数大于3,2月作答次数小于3再tag_cnt统计上会有问题
        group by uid, month(start_time)
        # 可以通过having做聚合后的判断,且不需要再select中体现
        having count(uid)>=3
    )
group by tag
order by count(tag) desc




全部评论

相关推荐

风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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