Counting the rows in a SQL Group By query
I recently needed count the number of rows in an SQL query that had a Group By clause. It looked something like this: SELECT account_name FROM events WHERE created_at >= CURDATE() – INTERVAL 3 MONTH GROUP BY account_id This provides a list of account names (28 in my case), but if you try to count them using: SELECT COUNT(account_name) as c FROM events WHERE created_at >= CURDATE() – INTERVAL 3 MONTH GROUP BY account_id You… continue reading.