【大厂真题】SQL28题解 | 被重复观看次数最多的3个视频
SELECT cid,pv,rk from ( select a.cid,sum(nums) as pv, ROW_NUMBER() OVER(order by sum(nums) desc,a.release_date desc) as rk ###排名问题 from course_info_tb a inner join ( select cid,uid,count(*) nums from play_record_tb group by cid,uid having count(*)>1 ) b on a.cid=b.cid group by a.cid,a.release_date ) t where rk<=3 order by rk asc
注意分区,不要加
limit 3也可以