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

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

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

with
    tag as (
        select
            ui.uid uid,
            level,
            count(start_time) - count(submit_time) incomplete_cnt,
            round(
                ifnull ((1 - count(submit_time) / count(start_time)), 0),
                3
            ) incomplete_rate,
            count(start_time) total
        from
            test.user_info ui
            left join test.exam_record er on ui.uid = er.uid
        group by
            ui.uid,
            level
    )
select
    uid,
    incomplete_cnt,
    incomplete_rate
from
    tag
where
    exists (
        select
            *
        from
            tag
        where
            level = 0
            and incomplete_cnt > 2
    )
    and level = 0
union all
select
    uid,
    incomplete_cnt,
    incomplete_rate
from
    tag
where
    not exists (
        select
            *
        from
            tag
        where
            level = 0
            and incomplete_cnt > 2
    )
    and total > 0
order by
    incomplete_rate asc

全部评论

相关推荐

湫湫湫不会java:1.在校经历全删了2.。这些荣誉其实也没啥用只能说,要的是好的开发者不是好好学生3.项目五六点就行了,一个亮点一俩行,xxx技术解决,xxx问题带来xxx提升。第一页学历不行,然后啥有价值的信息也没有,到第二页看到项目了,第一个项目九点,第二个项目像凑数的俩点。总体给人又臭又长,一起加油吧兄弟
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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