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

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

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

with data_f_use as (
    select uid, level
    , count(start_time) as total_cnt
    , count(submit_time) as completed
    , count(start_time) - count(submit_time) as incomplete_cnt
    from user_info left join exam_record using (uid)
    group by level, uid
)
    select uid, incomplete_cnt
    , ifnull(round(incomplete_cnt / total_cnt, 3), 0) as incomplete_rate
    from data_f_use
    where 
        if(
        (select max(incomplete_cnt) from data_f_use where level = 0) > 2, 
        (uid in (select uid from data_f_use where level = 0)),
        (uid in (select uid from exam_record where start_time is not null))
    )
    order by incomplete_rate 
这样好像简单点
全部评论

相关推荐

被加薪的哈里很优秀:应该继续招人,不会给你留岗位的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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