题解 | #未完成试卷数大于1的有效用户#

未完成试卷数大于1的有效用户

https://www.nowcoder.com/practice/46cb7a33f7204f3ba7f6536d2fc04286

select uid
        ,count(case when submit_time is null then 1 else null end) AS incomplete_cnt
        ,count(case when submit_time is not null then 1 else null end) AS complete_cnt
        ,group_concat(distinct concat(date(start_time),':',tag) separator ';') AS detail
from(
    select uid
            ,submit_time
            ,start_time
            ,tag
    from exam_record er
    left join examination_info ei
    on er.exam_id = ei.exam_id
    where year(start_time) = 2021
)exam
group by uid
having complete_cnt >= 1 and incomplete_cnt between 2 and 4
order by incomplete_cnt desc

全部评论
连接作答记录表和试卷信息表(为了得到tag),构成新的临时表exam,字段有uid,submit_time, start_time, tag。按用户uid分组,并且统计用户的作答情况,同时将同个uid组内的作答时间和tag都连接起来。
点赞 回复 分享
发布于 2023-05-30 17:09 美国

相关推荐

评论
点赞
收藏
分享

创作者周榜

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