题解 | #统计有未完成状态的试卷的未完成数和未完成率#

统计有未完成状态的试卷的未完成数和未完成率

https://www.nowcoder.com/practice/69fc2b1df4144c0991e4b8280d8aba27

with unfi as (
    select exam_id from exam_record where submit_time is null
),
unficnt as (# 未完成数量
    select exam_id, count(*) as ucnt from exam_record where submit_time is null
    group by exam_id
),
total as(
    select exam_id, count(*) as tcnt from exam_record r where r.exam_id in (select * from unfi) 
    group by exam_id
)

select uf.exam_id, ucnt, round(ucnt/tcnt, 3) from unfi uf left join unficnt uc on uf.exam_id = uc.exam_id
left join total tt on tt.exam_id = uf.exam_id
group by uf.exam_id, ucnt
order by uf.exam_id

老实用公用表表达式得了

全部评论

相关推荐

码农索隆:1.照片换成证件照。 2.专业技能写的太少了,太单薄了。 3.项目经历描写的太冗余,分成几点。 4.无实习经历,看看能不能包一个。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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