题解 | #每个题目和每份试卷被作答的人数和次数#
每个题目和每份试卷被作答的人数和次数
https://www.nowcoder.com/practice/203d0aed8928429a8978185d9a03babc
select * from ( select exam_id as tid, count(distinct uid) as uv, count(exam_id) as pv from exam_record group by exam_id order by pv desc ) as combinedform1 union select * from ( select question_id as tid, count(distinct uid) as uv, count(question_id) as pv from practice_record group by question_id order by pv desc ) as combinedform2
本题的是需要把question_id和exam_id的值结合到一个列表的属性中,需要通过union关键词,但是要考虑到在union组合后,子查询的排序是不会生效的,需要在子查询外再嵌套一层select,代码如上所示。