题解 | #SQL类别高难度试卷得分的截断平均值#
每个题目和每份试卷被作答的人数和次数
http://www.nowcoder.com/practice/203d0aed8928429a8978185d9a03babc
select * from
(select
exam_id tid
,count(DISTINCT uid) uv
,count(uid) pv
from exam_record
group by exam_id
order by uv desc,pv desc) a
union
select * from
(select
question_id tid
,count(DISTINCT uid) uv
,count(uid) pv
from practice_record
group by question_id
order by uv desc,pv desc) b
(select
exam_id tid
,count(DISTINCT uid) uv
,count(uid) pv
from exam_record
group by exam_id
order by uv desc,pv desc) a
union
select * from
(select
question_id tid
,count(DISTINCT uid) uv
,count(uid) pv
from practice_record
group by question_id
order by uv desc,pv desc) b
这里运用到union,和前面的答案比,更简单易懂。