Created
August 9, 2010 20:46
-
-
Save lqc/516088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT DISTINCT people.*, count(my_friends.guid_two) AS coincidence | |
| FROM entities people | |
| LEFT JOIN metadata | |
| ON (metadata.entity_guid = people.guid) | |
| LEFT JOIN relationships related_friends | |
| ON (related_friends.guid_two = people.guid) | |
| LEFT JOIN relationships my_friends | |
| ON (related_friends.guid_one = my_friends.guid_two) | |
| WHERE my_friends.guid_one = 'ME!' -- indirectly related to me | |
| AND my_friends.relation = 'friend' | |
| AND related_friends.guid_one != 'ME!' -- not related directly to me | |
| AND related_friends.relation = 'friend' | |
| AND (metadata.name = 'hobby' AND metadata.value IN ('sport', 'ksiazki')) -- IN my_hobbies | |
| GROUP BY my_friends.guid_two | |
| HAVING coincidence >= 1 | |
| ORDER BY coincidence DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment