难题丨又学到了各自排序怎么办
每个题目和每份试卷被作答的人数和次数
https://www.nowcoder.com/practice/203d0aed8928429a8978185d9a03babc?tpId=240&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Ftab%3DSQL%25E7%25AF%2587%26topicId%3D240
当然是各自建表排好序再union组合起来
SELECT * FROM
(SELECT
exam_id tid,
COUNT(DISTINCT uid)uv,
COUNT(*)pv
FROM
exam_record
GROUP BY exam_id
ORDER BY uv DESC,pv DESC)a
UNION
SELECT * FROM
(SELECT
question_id tid,
COUNT(DISTINCT uid)uv,
COUNT(*)pv
FROM
practice_record
GROUP BY question_id
ORDER BY uv DESC,pv DESC)b