题解 | #未完成试卷数大于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
全部评论

相关推荐

喜欢喜欢喜欢:这是我见过最长最臭的简历
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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