Reddit Users
Reddit is a social platform where users can join various communities called "subreddits". Users can subscribe to these subreddits to receive and interact with content that interests them. Each subreddit focuses on a specific topic or theme, and users can post content, comment, and upvote or downvote posts.
You can make use of the following tables:
user table:
user_subreddit table:
subreddit table:
Write a SQL query that returns subreddits that have more than 3 users subscribed to them. The results should have the columns subreddit_name and total_users. Order the results in descending order of total users.
To solve this, we can make use of a JOIN between the subreddit and user-subreddit tables. Then, you'd group the results by subreddit_id and name and filter those groups where the count is greater than 3.
SQLSELECT
s.name AS subreddit_name,
COUNT(us.user_id) AS total_users
FROM
subreddit s
JOIN
user_subreddit us ON s.subreddit_id = us.subreddit_id
GROUP BY
s.subreddit_id, s.name
HAVING
COUNT(us.user_id) > 3
ORDER BY
total_users DESC;
selectsub.name subreddit_name,count(distinct us.user_id) total_usersfrom user_subreddit as usleft join subreddit as subon us.subreddit_id = sub.subreddit_idgroup byus.subreddit_idhavingcount(distinct us.user_id) > 3