SELECT a.user_id, a.recommended_id FROM(select-- t1.*,t2.* from t1.user_id, t2.user_id as recommended_id,count(t2.song_id) as same_soung_cntfrom(select user_id ,song_id ,dayfrom leetcode.ex_1917_listens) t1join (select user_id ,song_id ,dayfrom leetcode.ex_1917_listens) t2 ON t1.user_id < t2.user_id and t1.song_id=t2.song_id and t1.day=t2.day group by t1.user_id,t2.user_idhaving same_soung_cnt>=3 ) aleft join (select user1_id,user2_id from leetcode.ex_1917_friendship ) bON a.user_id =b.user1_id WHERE a.recommended_id = b.user2_id -- change the join condition of the 1917 question;