题解 | #每个月Top3的周杰伦歌曲#

每个月Top3的周杰伦歌曲

https://www.nowcoder.com/practice/4ab6d198ea8447fe9b6a1cad1f671503

select month,ranking,song_name,play_pv
from
(
    select month(fdate) month,row_number() over(partition by month(fdate) order by count(t1.song_id) desc,t1.song_id) ranking,song_name,count(t1.song_id) play_pv
    from (play_log t1 join song_info t2 
    on t1.song_id=t2.song_id)  join user_info t3
    on t1.user_id=t3.user_id
    where age between 18 and 25 and year(fdate)='2022' and singer_name='周杰伦'
    group by month(fdate),song_name,t1.song_id) t
where ranking<=3;#2/3用例通过,顺序问题~在窗口函数里加song_id相关排序,此时聚合函数处也要加

全部评论

相关推荐

2025-12-13 14:51
已编辑
井冈山大学 算法工程师
龙虾x:算法比你强的没有你美,比你美的…..算了已经没有比你美的了
工作两年想退休了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务