with t as(
select user2_id user1_id,user1_id user2_id
from friendship
union all
select user1_id user1_id,user2_id user2_id
from friendship
)
select distinct t1.user1_id, t2.user1_id as user2_id,count(*)as common_friend from
t t1 inner join t t2 on t1.user2_id=t2.user2_id and t1.user1_id!=t2.user1_id and t1.user1_id<t2.user1_id
where (t1.user1_id,t2.user1_id)in
(
select *from t
)
group by (t1.user1_id,t2.user1_id)
having count(*)>=3