题解 | #每个题目和每份试卷被作答的人数和次数#
每个题目和每份试卷被作答的人数和次数
http://www.nowcoder.com/practice/203d0aed8928429a8978185d9a03babc
-- 题目不难,但是有一个易错点,即union连接的两部分单独排序的时候,只分别加 order by 是不行的,会报错,而在union后加的order by 是默认对全局排序的,所以我想到了把两个部门分别加 order by 后再分别加个括号,结果发现虽然没有报错但是括号并没有作用,偶排序并不对,然后我就懵了,后面看了别人的答案才知道 加完括号还要用select * 外嵌才能让排序生效~~~ 以下为正确代码: select * from ( select exam_id as tid,count(distinct uid) as uv,count() as pv from exam_record group by exam_id order by uv desc,pv desc) a union select * from ( select question_id as tid,count(distinct uid) as uv,count() as pv from practice_record group by question_id order by uv desc,pv desc) b;