Commit e5d3d06a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve sql query to remove duplicates for roles stats

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 316c9044
......@@ -5,18 +5,22 @@ module EE
module ClassMethods
def roles_stats
connection.execute <<-EOF.strip_heredoc
SELECT CASE max(access_level)
WHEN 10 THEN 'guest'
WHEN 20 THEN 'reporter'
WHEN 30 THEN 'developer'
WHEN 40 THEN 'master'
WHEN 50 THEN 'owner'
ELSE 'unknown' END
AS kind,
count(DISTINCT user_id) AS amount
FROM #{table_name}
SELECT CASE access_level
WHEN 10 THEN 'guest'
WHEN 20 THEN 'reporter'
WHEN 30 THEN 'developer'
WHEN 40 THEN 'master'
WHEN 50 THEN 'owner'
ELSE 'unknown' END
AS kind,
count(*) AS amount
FROM (
SELECT user_id, max(access_level) AS access_level
FROM #{table_name}
GROUP BY user_id
) access_per_user
GROUP BY access_level
ORDER BY amount DESC;
ORDER BY access_level ASC;
EOF
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment