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

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

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

select uid,b,c
from
    (select u.uid,u.level,count(e.start_time) a,count(e.start_time)-count(e.submit_time) b,
    case when count(e.start_time)=0 then 0.000 else round((count(e.start_time)-count(e.submit_time))/count(e.start_time),3) end c
    from user_info u left join exam_record e
    on u.uid=e.uid group by u.uid) a
where case when 2<
    (select count(e.start_time)-count(e.submit_time)k from user_info u left join exam_record e on u.uid=e.uid   where u.level=0 group by u.uid order by k desc limit 1 )
    then uid in 
    (select uid from user_info where level=0)
    else uid in
    (select distinct uid from exam_record) end
order by c;

小白学到了在where筛选语句中 case when的使用!

全部评论
就那样吧 笨
点赞 回复 分享
发布于 02-20 22:17 上海
真厉害 爱了爱了
点赞 回复 分享
发布于 02-28 11:03 日本

相关推荐

11-28 17:58
门头沟学院 Java
美团 JAVA开发 n×15.5
牛客786276759号:百度现在晋升很难的 而且云这块的业务没美团好 你看百度股价都跌成啥样了
点赞 评论 收藏
分享
牛客717484937号:双飞硕没实习挺要命的
点赞 评论 收藏
分享
评论
2
收藏
分享
牛客网
牛客企业服务