diff --git a/comments/examples.sql b/comments/examples.sql index 5d92fdf4bc79e8e53f87b315b6ca222824baa720..e581af1df53354503bc53409044a0d40bdbf8b5a 100644 --- a/comments/examples.sql +++ b/comments/examples.sql @@ -41,3 +41,43 @@ GROUP BY users.id ORDER BY votes DESC LIMIT 10; +-- get users with most downvotes + +SELECT + users.username, + SUM(c.vote) AS votes +FROM users LEFT JOIN voted_comments c ON c.user_id = users.id +GROUP BY users.id +HAVING votes IS NOT NULL +ORDER BY votes ASC +LIMIT 10; + +-- get users with most comments + +SELECT + users.username, + COUNT(*) AS comment_count +FROM users LEFT JOIN visible_comments c ON c.user_id = users.id +GROUP BY users.id +ORDER BY comment_count DESC +LIMIT 10; + +-- get users with most edits + +SELECT + users.username, + COUNT(*) AS updates_count +FROM users LEFT JOIN updates u ON u.user_id = users.id +GROUP BY users.id +ORDER BY updates_count DESC +LIMIT 10; + +-- get all moderators, sorted by comment counts + +SELECT + username, + COUNT(*) AS comment_count +FROM users LEFT JOIN visible_comments c ON c.user_id = users.id +WHERE users.moderator = 1 +GROUP BY users.id +ORDER BY comment_count DESC;