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

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

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

select distinct
		if(q.max_value>2,q.uid,qq.uid) as uid,
		if(q.max_value>2,q.incomplete_cnt,qq.incomplete_cnt) as incomplete_cnt,
		if(q.max_value>2,if(q.incomplete_rate is null, 0, q.incomplete_rate),if(qq.incomplete_rate is null,0,qq.incomplete_rate)) as incomplete_rate
from
(
select ui.uid,
		count(if(submit_time is null and start_time is not null,1,null)) as incomplete_cnt,
		round(count(if(submit_time is null and start_time is not null,1,null)) /count(start_time),3) as incomplete_rate,
		max(count(if(submit_time is null and start_time is not null,1,null))) over () as max_value
from exam_record er right join user_info ui
on er.uid = ui.uid
where `level` = 0
group by ui.uid
) q,
(
select ui.uid,
		count(if(submit_time is null and start_time is not null,1,null)) as incomplete_cnt,
		round(count(if(submit_time is null and start_time is not null,1,null)) /count(start_time),3) as incomplete_rate
from exam_record er right join user_info ui
on er.uid = ui.uid
where start_time is not null#是有作答记录
group by ui.uid
) qq
order by incomplete_rate;
全部评论

相关推荐

屌丝逆袭咸鱼计划:心态摆好,man,晚点找早点找到最后都是为了提升自己好进正职,努力提升自己才是最关键的😤难道说现在找不到找的太晚了就炸了可以鸡鸡了吗😤早实习晚实习不都是为了以后多积累,大四学长有的秋招进的也不妨碍有的春招进,人生就这样
点赞 评论 收藏
分享
05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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