题解 | #SQL类别高难度试卷得分的截断平均值#
月均完成试卷数不小于3的用户爱作答的类别
http://www.nowcoder.com/practice/b1d13efcfa0c4ecea517afbdb9090845
select
tag
,count(tag) tag_cnt
from exam_record r
join examination_info i
on r.exam_id=i.exam_id
where uid in (
select uid
from exam_record
where submit_time is not null
group by uid
having count(exam_id) / count(distinct DATE_FORMAT(start_time, "%Y%m")) >= 3
)
group by tag
tag
,count(tag) tag_cnt
from exam_record r
join examination_info i
on r.exam_id=i.exam_id
where uid in (
select uid
from exam_record
where submit_time is not null
group by uid
having count(exam_id) / count(distinct DATE_FORMAT(start_time, "%Y%m")) >= 3
)
group by tag
order by tag_cnt desc
这题相当于大总结,需要理清楚关系。