--本问题大致可以用这个思路:
--1.筛选条件:用户年龄(18-25)、时间(2022)、歌手(周杰伦)、排名(前三名)
--2.所需的函数:YEAR、ROW_NUMBER
--3.组装:观察输出可发现,三首歌均为周杰伦的,因此前三个条件可以同时出现,采用子查询的方式,在FROM中把三个表进行连接,在WHERE中将三个条件罗列出来,再通过这三个属性month (fdate),song_name,song_id作为GROUP BY的分组条件(为什么用这三个呢?观察题目样例输出,不难发现,都是先按月份进行分组,月份相同,再按歌曲分组。这个song_id纯粹是后面加的,因为我发现提交的时候有两行在顺序上一直报错,偷看别人的题解发现是按照song_id排列的,这个不加还不行,因为在ROW_NUMBER里要order by一下song_id)。
--4.最终筛选:使用WHERE将ranking前三的歌曲及其信息筛选出来再来一个order by即可
select
    month,
    ranking,
    song_name,
    play_pv
from
    (
        select
            month (a.fdate) as month,
            row_number() over (
                partition by
                    month (a.fdate)
                order by
                    count(b.song_name) desc,
                    b.song_id asc
            ) as ranking,
            b.song_name as song_name,
            count(b.song_name) as play_pv
        from
            play_log as a
            left join song_info as b on a.song_id = b.song_id
            left join user_info as c on a.user_id = c.user_id
        where
            c.age between 18 and 25
            and year (a.fdate) = '2022'
            and b.singer_name = '周杰伦'
        group by
            month (a.fdate),
            b.song_name,
            b.song_id
    ) as goal
where
    ranking between 1 and 3
order by
    month asc,
    play_pv desc

刚学没多久,希望能给别人带来帮助,如果我考虑的有所欠缺,求大牛不吝指点,谢谢啦