知识点

  1. 使用子查询首先推荐用户1关注的人就是follow表user_id=1的follower_id
  2. 之后音乐不能是用户1听过的,就是music_id not in(music_likes表里面user_id = 1)
  3. 最后再把music表连接一下,music_name不要重复再加个distinct

代码

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