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

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

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

SELECT
  uid,
  COUNT(incomplete) incomplete_cnt,
  COUNT(complete) complete_cnt,
  GROUP_CONCAT(
    DISTINCT CONCAT_WS(':', DATE(start_time), tag) SEPARATOR ';'
  ) detail
FROM
  (
    SELECT
      er.uid uid,
      ei.tag tag,
      er.start_time start_time,
      IF(submit_time IS NULL, 1, NULL) incomplete,
      IF(submit_time IS NULL, NULL, 1) complete
    FROM
      exam_record er
      INNER JOIN examination_info ei ON er.exam_id = ei.exam_id
    WHERE
      YEAR(start_time) = 2021
  ) tb
GROUP BY
  uid
HAVING
  complete_cnt >= 1
  AND incomplete_cnt BETWEEN 2 AND 4
ORDER BY
  incomplete_cnt DESC;

全部评论

相关推荐

评论
3
收藏
分享

创作者周榜

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