开发者

Help needed to construct a SQL query

Need your help to get the list of suggested friends (who aren't friends of the current user but开发者_StackOverflow are friends of 2 or more of the current user's friends). The primary ordering should put people at the same school at the top, and the secondary ordering should put people with more common friends (that is, the number of people who are friends of that person and the current user) near the top.

Users: user_id PK, user_name

Profiles: user_id PK, school_name, ...

Friendships: id PK, user_id FK, friend_id FK

Thank you in advance.

Joe

This is not a homework question. I am currently working on a site and my solution seems not efficient enough. That's why I need you suggestions. Thanks.


(I'm assuming HW here.)

Seems like if you queried for a list of all of your friends' friends, and checked for the friends-of-friends that weren't unique in that list, you'd be getting somewhere.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜