/*
select follower_id
from follow
where user_id = 1;
select music_id
from music_likes as ml
where user_id = 1;
select music_id
from music_likes as ml
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);
*/
select music_name
from music
where id in (
select music_id
from music_likes as ml
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)
)
order by id;
我相信,这道题一定有其他看似简单的解答方法。但是,这道题我还是倾向于运用到经典的剥洋葱思路。
- 第一步:寻找
user_id=1
的关注者; - 第二步:寻找
user_id=1
喜欢的music_id
; - 第三步:检索
user_id=1
的关注者喜欢的music_id
,并排除第二步中的检索结果; - 第四步:根据
id
检索music_name
,并排序。