题解 | #未完成试卷数大于1的有效用户#

未完成试卷数大于1的有效用户

http://www.nowcoder.com/practice/46cb7a33f7204f3ba7f6536d2fc04286

这道题很综合,有几个关键点

第一点:concat_ws将 日期和tag连接

第二点: group_concat,注意要distinct

select uid,
         sum(CASE WHEN submit_time is null then 1 else 0 end) as incomplete_cnt,
       count(submit_time) as complete_cnt,
       group_concat(DISTINCT detail separator ';')
FROM
    (SELECT uid, e1.exam_id, start_time,
    submit_time,score,tag,
    concat_ws(':',DATE_FORMAT(start_time,'%Y-%m-%d'),tag) as detail
    FROM exam_record e1
    LEFT JOIN examination_info e2
    ON e1.exam_id = e2.exam_id
    where year(start_time)='2021')a
GROUP BY uid
having count(submit_time) >=1
and sum(CASE WHEN submit_time is null then 1 else 0 end) between 2 and 4
全部评论

相关推荐

我就是0offer糕手:北大不乱杀
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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