这题也不是很难,就是有点绕,为啥通过率1这么低。。。
最内侧筛选出id为1的人喜欢的歌的id,然后外面的查询去掉并且查询id为1的人关注的人喜欢的歌id并连接,distinct保证不重复,
最后按照id升序
select music_name
from(
select distinct music_name,id
from music,(
select music_id
from follow a,music_likes b
where a.user_id=1 and a.follower_id=b.user_id and music_id not in(
select music_id
from music_likes
where user_id=1
)
)a
where music.id=a.music_id
)a
order by id asc

京公网安备 11010502036488号