CodingNeed.

3 · Connect and build · 20 MIN

Project · Spending report

Project · Spending report.

Build a report with one row per category: category, total amount, and transaction count. Sort by highest total, then category alphabetically for ties. Test the whole data shape as well as values.

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 ORDER BY category;
Check the expected output
[["food",12],["travel",3]]

Your challenge

Return category, SUM(amount), COUNT(*) ordered by total descending, then category ascending.

Common trap

Row order is only guaranteed with ORDER BY.