Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SELECT "targets_user"."id", "targets_user"."password", "targets_user"."last_login",
...
"targets_user"."date_of_birth", "targets_user"."zodiac_sign",
(COUNT(DISTINCT "targets_match"."id") + COUNT(DISTINCT T4."id")) AS "num_matches",
CASE WHEN ((COUNT(DISTINCT "targets_match"."id") + COUNT(DISTINCT T4."id")) > 0
AND (COUNT(DISTINCT "targets_match"."id") + COUNT(DISTINCT T4."id")) > 5
AND "targets_user"."zodiac_sign" = \'taurus\') THEN 15
WHEN ((COUNT(DISTINCT "targets_match"."id") + COUNT(DISTINCT T4."id")) > 0
AND (COUNT(DISTINCT "targets_match"."id") + COUNT(DISTINCT T4."id")) > 5) THEN 10
WHEN ((COUNT(DISTINCT "targets_match"."id") + COUNT(DISTINCT T4."id")) > 0
AND "targets_user"."zodiac_sign" = \'taurus\') THEN 10
WHEN (COUNT(DISTINCT "targets_match"."id") + COUNT(DISTINCT T4."id")) > 0 THEN 5
WHEN "targets_user"."zodiac_sign" = \'taurus\' THEN 5
ELSE 0 END AS "score"
FROM "targets_user" LEFT OUTER JOIN "targets_target" ON ("targets_user"."id" = "targets_target"."user_id")
LEFT OUTER JOIN "targets_match" ON ("targets_target"."id" = "targets_match"."target_1_id")
LEFT OUTER JOIN "targets_match" T4 ON ("targets_target"."id" = T4."target_2_id")
GROUP BY "targets_user"."id"
ORDER BY "score" DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment