题解 | 根据指定记录是否存在输出不同情况

根据指定记录是否存在输出不同情况

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

select ui.uid,
count(if(start_time is not null and score is null,1,null)) as incomplete_cnt,
round(avg(if(start_time is not null and score is null,1,0)),3) as incomplete_rate
from user_info ui
left join exam_record er on ui.uid = er.uid

where case when
(select max(num) from
(select count(if(start_time is not null and score is null,1,null)) as num
from user_info ui
 join exam_record er on ui.uid = er.uid
where level=0
group by ui.uid)a)>2
then ui.uid in(select uid from user_info where level =0)
else ui.uid in (select uid from user_info where start_time is not null)
end

group by ui.uid
order by incomplete_rate

此题无思路 where还能搭配case when 这么玩

全部评论

相关推荐

12-28 09:59
复旦大学 Java
点赞 评论 收藏
分享
11-03 13:01
西南大学 Java
mengnankk:28不要投让27的先投,先投带动后投
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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