--1.统计月均完成数大于3的用户
WITH t AS (
SELECT
er.*,
ei.tag,
count( score ) over ( PARTITION BY uid, DATE_FORMAT( submit_time, '%Y%m' ) ) AS score_num
FROM
exam_record er
JOIN examination_info ei ON er.exam_id = ei.exam_id
)
SELECT
er.*,
ei.tag,
count( score ) over ( PARTITION BY uid, DATE_FORMAT( submit_time, '%Y%m' ) ) AS score_num
FROM
exam_record er
JOIN examination_info ei ON er.exam_id = ei.exam_id
)
--2.统计这些用户完成试卷的类别及相应次数,次数包括未完成
SELECT
tag,
count( start_time ) tag_cnt
FROM
t
WHERE
uid IN ( SELECT uid FROM t WHERE score_num >= 3 )
GROUP BY
exam_id
ORDER BY
tag_cnt DESC
tag,
count( start_time ) tag_cnt
FROM
t
WHERE
uid IN ( SELECT uid FROM t WHERE score_num >= 3 )
GROUP BY
exam_id
ORDER BY
tag_cnt DESC