select * from (select month(p.fdate) `month`, row_number()over(partition by month(fdate) order by count(p.user_id) desc, p.song_id asc) ranking, song_name, count(p.user_id) play_pv from play_log p left join song_info s on p.song_id = s.song_id left join user_info u on p.user_id = u.user_id where s.singer_name = '周杰伦' and (u.age between 18 and 25) group by month(p.fdate), p.song_id, song_name) a where ranking in (1,2,3)