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


全部评论

相关推荐

09-22 09:42
门头沟学院 Java
牛客37185681...:马德,我感觉这是我面过最恶心的公司,一面是两个女hr,说什么实习前几个月属于试用期,试用期过了才能转成正式实习生,我***笑了,问待遇就是不说,问能不能接受全栈,沙币公司
如果可以选,你最想去哪家...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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