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

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

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

with cte_m as
(select 
    distinct a.*,b.tag
from
    exam_record a
left join  examination_info b
on a.exam_id = b.exam_id
where substring(start_time,1,4)='2021')
select
    uid,
    count(start_time)-count(submit_time) as incomplete_cnt,
    count(submit_time) as cnt_d,
    group_concat(distinct concat_ws(':',date(start_time),tag) separator ';') as detail
from cte_m
group by uid
having cnt_d >=1 and incomplete_cnt <5 and  incomplete_cnt>1
order by incomplete_cnt desc;

先创建一个临时表cte_m,方便后续查询。接着对查询出有效用户uid=1002。这里用到了一个聚合函数group_concat(字段名 separator '分隔符'),对一个分组中的值进行组合。

全部评论

相关推荐

但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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