select *
from
(
select
exam_id as tid,
count(distinct uid) as uv,
count(uid) as pv
from
exam_record
group by
exam_id
order by
uv desc,
pv desc
) as t1
union all
select *
from
(
select
question_id as tid,
count(distinct uid) as uv,
count(uid) as pv
from
practice_record
group by
question_id
order by
uv desc,
pv desc
) as t2
# 本题考察的是对合并表之前的表进行分别排序,除了上面代码使用的在子查询中使用临时表进行排序之外,还可以在合并之后按照顺序对tid的首个字符进行排序:left(tid,1),uv,pv

京公网安备 11010502036488号