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

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

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

不知道为什么格式化之后运行不了

难点

  1. sum 结合 if 计算 (用sum case也可)
  2. group_concat(distinct concat_ws(':',date(start_time),tag) separator ';') as detail
  3. group_concat: 这是一个SQL聚合函数,用于将多行数据合并成一个字符串,通常用于将某一列的值连接起来。在这里,它将被连接的值来自于下一个部分。
  4. distinct: 这个关键字指示在连接之前先去除重复的值。这意味着如果有重复的数据行,只会保留一个。
  5. concat_ws(':', date(start_time), tag): 这部分将两个值连接在一起。concat_ws 是一个函数,它以指定的分隔符将参数中的值连接在一起。在这里,分隔符是冒号 ':'。参数包括两个值:date(start_time) 和 tag。date(start_time): 这是一个将 start_time 列中的日期部分提取出来的函数。它将日期转换为特定的格式。tag: 这可能是一个标签或标识符,用于标识数据的某种特征。
  6. separator ';': 这是用来指定连接后的值之间的分隔符。在这里,分隔符是分号 ';'。
  7. as detail: 这是给合并后的结果取一个别名,即将连接后的字符串赋予一个名为 detail 的列名。
select er.uid,
       sum(if(submit_time is null,1,0)) as incomplete_cnt,
       sum(if(submit_time is not null,1,0)) as complete_cnt,
       group_concat(distinct concat_ws(':',date(start_time),tag) separator ';') as detail
from exam_record er left join examination_info ei on er.exam_id = ei.exam_id where year(start_time)=2021
group by er.uid
having complete_cnt>=1 and incomplete_cnt<5 and incomplete_cnt>1
order by incomplete_cnt desc;

全部评论

相关推荐

点赞 评论 收藏
分享
吴offer选手:我卡在笔试才是最好笑的,甚至没给我发过笔试链接
投递哔哩哔哩等公司6个岗位
点赞 评论 收藏
分享
评论
4
1
分享

创作者周榜

更多
牛客网
牛客企业服务