这道题的坑在于两个order by的query不能用union连接,只可以连接起来后再统一进行排序。所以我把原本的查询变成子查询,套个壳就好了
select a.tid, a.uv, a.pv from
(select exam_id as tid, count(distinct uid) as uv, count(start_time) as pv
from exam_record
group by tid
order by uv desc, pv DESC) as a
union all
select b.tid, b.uv, b.pv from
(select question_id as tid, count(distinct uid) as uv, count(submit_time) as pv
from practice_record
group by tid
order by uv desc, pv DESC) as b