CodingNeed.

2 · Summarize · 8 MIN

Filter groups

Filter groups.

WHERE filters rows before grouping. HAVING filters groups after aggregates are calculated. You can group by category, then keep only categories with enough transactions.

Think of a spreadsheet: select columns, keep relevant rows, and summarize the result.

Read the example

SELECT category, SUM(amount) FROM expenses GROUP BY category HAVING SUM(amount) > 5 ORDER BY category;
Check the expected output
[["food",12]]

Your challenge

Return category and total amount for categories with at least two rows, ordered by category.

Common trap

Row order is only guaranteed with ORDER BY.

Next lesson: Connect related data →

Essential cookies keep your account signed in. Optional analytics is not configured on this site. Your choice does not affect access to lessons.

Read the Privacy Policy. You can change this choice in the footer.