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

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

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

with temp as(
select t.uid,level,sum(start_time is not null and submit_time is null) as incomplete_cnt,
        round(sum(start_time is not null and submit_time is null)/count(1),3) as incomplete_rate,
        count(exam_id) as num
    from user_info t
    left join exam_record t1
    using(uid)
    group by t.uid)

select uid,incomplete_cnt,incomplete_rate
from temp
where exists(select uid from temp where incomplete_cnt > 2 and level = 0) and level = 0
union all
select uid,incomplete_cnt,incomplete_rate
from temp
where not EXISTS (
    select uid from temp where level=0 and incomplete_cnt>2
) and num>0
order by incomplete_rate

全部评论

相关推荐

勇敢的90后想交流:我愿意付费上班,楼主你就安心字节待着吧,我是真的喜欢上班
点赞 评论 收藏
分享
苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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