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

每个月Top3的周杰伦歌曲

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

with a as(                               --创建临时表,用于进行查询top3的操作
select month(t1.fdate) as month,t3.song_id,
t3.song_name song_name,count(*) play_pv
from(
    select fdate,user_id,song_id         --时间是2022年的
    from play_log 
    where year(fdate)=2022
)as t1,(
    select user_id,age                   --用户年龄是18-25岁之间的
    from user_info
    where age between 18 and 25
)as t2,(
    select song_id,song_name             --歌曲是周杰伦的 
    from song_info
    where singer_name='周杰伦'
)as t3
where t1.user_id=t2.user_id and t1.song_id=t3.song_id
group by month,t3.song_name,t3.song_id   --按照月份、歌曲名字,歌曲Id进行分组
order by month asc,play_pv desc,t3.song_id asc--分组后,按照月份、播放次数、歌曲Id进行分组
)
select b.month,b.ranking,b.song_name,b.play_pv
from(
    select *,ROW_NUMBER() over(partition by a.month order by a.play_pv desc) as ranking
	--ROW_NUMBER()窗口函数的用法
    from a
)b
where b.ranking<=3                      







全部评论

相关推荐

03-03 23:12
已编辑
北京邮电大学 Java
书海为家:我来给一点点小建议,因为毕竟还在学校不像工作几年的老鸟有丰富的项目经验,面试官在面试在校生的时候更关注咱们同学的做事逻辑和思路,所以最好在简历中描述下自己做过项目的完整过程,比如需求怎么来的,你对需求的解读,你想到的解决办法,遇到困难如何找人求助,最终项目做成了什么程度,你从中收获了哪些技能,你有什么感悟。
你的简历改到第几版了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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