# 先分别设计子查询来查询每个题目和每份试卷被作答的人数和次数并排序
# 然后查询已排序的结果并使用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
) k1
union
select * from (
select question_id, count(distinct uid) uv, count(*) pv
from practice_record
group by question_id
order by uv desc, pv desc
) k2
sql执行顺序:
from-on-join-where-group by-having-select-union-order by-limit



京公网安备 11010502036488号