More readable SQL query.

This commit is contained in:
Andreas Brandl 2018-02-21 13:54:35 +01:00
parent 3dbec2c285
commit b25319f92b
1 changed files with 7 additions and 3 deletions

View File

@ -38,9 +38,13 @@ class MembersFinder
<<~SQL
SELECT DISTINCT ON (user_id, invite_email) member_union.*
FROM (#{union.to_sql}) AS member_union
ORDER BY
user_id, invite_email,
CASE WHEN type = 'ProjectMember' THEN 1 WHEN type = 'GroupMember' THEN 2 ELSE 3 END
ORDER BY user_id,
invite_email,
CASE
WHEN type = 'ProjectMember' THEN 1
WHEN type = 'GroupMember' THEN 2
ELSE 3
END
SQL
else
# Older versions of MySQL do not support window functions (and DISTINCT ON is postgres-specific).