题解 | #每个题目和每份试卷被作答的人数和次数#
每个题目和每份试卷被作答的人数和次数
https://www.nowcoder.com/practice/203d0aed8928429a8978185d9a03babc
#统计 每个题目 每份试卷 被作答人数 和次数 分别按照试卷和题目的uv pv 降序显示
select *
from(
select exam_id tid,count(distinct uid) uv,count(exam_id) pv
from exam_record
group by exam_id
order by uv desc, pv desc
) a1
union
select *
from (
select question_id tid,count(distinct uid) uv,count(question_id) pv
from practice_record
group by question_id
order by uv desc, pv desc
) a2;
不能只是简单的通过union连接,最终的排序仍存在问题。而一段代码中又只能有一行order by指令,所以考虑要把查询表用作子表进行查询,能够在每个子表中进行order by排序,在最后union
查看16道真题和解析