和大家分享一下我的解题思路,抛砖引玉

首先三表连接

select a.user_id , a.follower_id , b.music_id , c.music_name
from follow a
left join music_likes b on a.follower_id = b.user_id
left join music c on b.music_id = c.id

找出题目要求的用户已经喜欢的音乐 select a.user_id,music_name rom music_likes a left join music b on a.music_id = b.id

整合代码,用not in 排除掉这些用户和音乐, 在添加上题目要求的 user_id =1 与排序 即可

完整代码:

select distinct music_name
from follow a
left join music_likes b
on a.follower_id = b.user_id
left join music c
on b.music_id = c.id
where (a.user_id,music_name) not in (select a.user_id,music_name
                                    from music_likes a
									left join music b
									on a.music_id = b.id)
and a.user_id = 1
order by music_id