像这样的东西.
Select people.id, people.name, count(interest.id)
from people
left join people_interests on people.id = people_interests.peopleid
left join interests on people_interests.interestid = interests.interest.id
where interests.id in (select id from interests where interests.peopleid = @inputuserid)
group by people.id, people.name
order by count(interest.id)
英语(可能会或可能不会更清楚.)
>选择人员姓名和他们共享的兴趣数量
>从人员表
>加入那个表的兴趣表
>只是我们想要匹配的人的利益.
>(按人群分组
>并按匹配的兴趣数量排序.)
更新没有子查询但不太清楚
Select people.id, people.name, count(interest.id)
from people
left join people_interests on people.id = people_interests.peopleid
left join interests on people_interests.interestid = interests.interest.id
inner join interest i2 on (interests.id = i2.id and i2.people_id = @inputuserid)
group by people.id, people.name
order by count(interest.id)