题解 | 每个月Top3的周杰伦歌曲
每个月Top3的周杰伦歌曲
https://www.nowcoder.com/practice/4ab6d198ea8447fe9b6a1cad1f671503
select
month,
ranking,
song_name,
play_pv
from
(
select
month,
row_number() over (
partition by
month
order by
play_pv desc,
t.song_id asc
) as ranking,
song_name,
play_pv
from
(
select
month(fdate) as month,
count(*) as play_pv,
pl.song_id
from
play_log pl
inner join song_info si on pl.song_id = si.song_id
inner join user_info ui on ui.user_id = pl.user_id
where
year(fdate) = 2022
and age >= 18
and age <= 25
and singer_name = "周杰伦"
group by
month(fdate),
pl.song_id
) as t
inner join song_info si on si.song_id = t.song_id
) as t
where
ranking <= 3;
