题解 | #根据指定记录是否存在输出不同情况#
根据指定记录是否存在输出不同情况
https://www.nowcoder.com/practice/f72d3fc27dc14f3aae76ee9823ccca6b
select uid,b,c
from
(select u.uid,u.level,count(e.start_time) a,count(e.start_time)-count(e.submit_time) b,
case when count(e.start_time)=0 then 0.000 else round((count(e.start_time)-count(e.submit_time))/count(e.start_time),3) end c
from user_info u left join exam_record e
on u.uid=e.uid group by u.uid) a
where case when 2<
(select count(e.start_time)-count(e.submit_time)k from user_info u left join exam_record e on u.uid=e.uid where u.level=0 group by u.uid order by k desc limit 1 )
then uid in
(select uid from user_info where level=0)
else uid in
(select distinct uid from exam_record) end
order by c;
小白学到了在where筛选语句中 case when的使用!


阿里巴巴公司氛围 651人发布