Threads Flagged Yesterday
Problem
A discussion forum logs every moderation action members take on threads.
Table: moderation
+-------------+--------------+
| Column Name | Type |
+-------------+--------------+
| member_id | int |
| thread_id | int |
| acted_on | date |
| action | varchar(255) |
| note | varchar(255) |
+-------------+--------------+
Each row records one moderation action. When action is 'flag', the note column holds the flag reason (for example 'spam' or 'hate'); for other actions note may be NULL.
Write a solution to report, for each flag reason, how many distinct threads were flagged yesterday. Assume today is 2023-07-05, so yesterday is 2023-07-04. Only include reasons that had at least one flagged thread. Return columns flag_reason and thread_count in any order.
Tables
Example rows — the live problem includes the full dataset.
| member_id | thread_id | acted_on | action | note |
|---|---|---|---|---|
| 1 | 1 | 2023-07-01 | view | |
| 1 | 1 | 2023-07-01 | upvote | |
| 2 | 4 | 2023-07-04 | flag | spam |
Expected output
Your answer should return 2 rows with the columns flag_reason, thread_count.
Starter code (SQL)
SELECT *
FROM moderation;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock