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

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

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

#sql的关键是读题,错了好多次才发现对年份有要求,
#其次是这题的分组拼接,不能输出重复数据,输出要按照时间顺序,题干未作说明
#count只负责计数,但是会跳过null,如果if的F不设置为null,本题就错了,不过使用sum的话
#将if设置为1,0完全可以
select uid,count(if(submit_time is null, 1,null)) as incomplete_cnt,count(if(submit_time is not null, 1,null)) as complete_cnt,GROUP_CONCAT(distinct CONCAT(DATE(start_time), ':', tag) order by start_time  SEPARATOR ';') AS detail
from  exam_record ee
###count是计数,会忽略null,只要非空就会计数,
#如果是sum,则要将if的null改成0
inner join examination_info as e on e.exam_id = ee.exam_id
where year(start_time)=2021
group by uid
having count(if(submit_time is not null, 1,null))>=1 
and count(if(submit_time is null, 1,null)) <5 
and count(if(submit_time is null, 1,null)) >1
order by incomplete_cnt desc


全部评论

相关推荐

点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
我的简历长这样
点赞 评论 收藏
分享
Lorn的意义:你这标个前端是想找全栈吗?而且项目确实没什么含金量,技术栈太少了,边沉淀边找吧 现在学院本想就业好一点四年至少得高三模式两年加油吧
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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