From 6f16f2440165ade9afab346046f2f110fa3373f7 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Fri, 24 Aug 2012 17:17:05 +0300 Subject: [PATCH] Add a few more interesting example queries. --- comments/examples.sql | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/comments/examples.sql b/comments/examples.sql index 5d92fdf4..e581af1d 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; -- GitLab