I’m not really an expert at queries. What I need is a list of usernames of the users with the most (highest number) of flagged posts (flags that have been approved by a moderator) and display this information in order much like the example below:
SELECT u.username "Username", COUNT(pa.agreed_at) "Flag Count"
FROM post_actions pa
JOIN posts p ON pa.post_id = p.id
JOIN users u ON p.user_id = u.id
WHERE pa.agreed_at IS NOT NULL
GROUP BY u.username
ORDER BY "Flag Count" DESC