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

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

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

with a as
(
select uid,level,sum(case when start_time is not null and submit_time is null then 1 else 0 end) as incomplete_cnt,count(start_time) as cnt,ifnull(round(sum(case when start_time is not null and submit_time is null then 1 else 0 end)/count(start_time),3),0)  as incomplete_rate
from exam_record
right join user_info
using (uid)
group by uid
)
select uid,incomplete_cnt,incomplete_rate from a
where exists
(select uid from a
where incomplete_cnt>2 and level=0) and level=0 
union all
select uid,incomplete_cnt,incomplete_rate from a
where not exists
(select uid from a
where incomplete_cnt>2 and level=0)
and cnt>0
order by incomplete_rate

全部评论

相关推荐

点赞 评论 收藏
分享
04-10 11:56
如皋中学 Java
高斯林的信徒:双c9能简历挂的?
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务