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

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

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

10行代码搞定

with cte as(
select count(start_time)-count(submit_time) as non_0_num
from exam_record
where uid in (select distinct uid from user_info where level=0) )
#计算出0级用户未完成的试卷量
select if((select* from cte)>2,uid in (select distinct uid from user_info where level=0),uid) as uid,
#if(expr,v1,v2)函数,v1中加入uid范围条件,注意不要直接引用cte,然后就是基操了
count(start_time)-count(submit_time) as non_num,
round((count(start_time)-count(submit_time))/count(start_time),3) as non_rate
from exam_record
group by uid
order by non_rate;

alt

全部评论
错的
点赞 回复 分享
发布于 2021-12-10 15:26
select* from cte求出来的是所有0级用户的未完成量
点赞 回复 分享
发布于 2022-01-09 22:54

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务