CodingNeed.

2 · Summarize · 8 MIN

Aggregate a result

Aggregate a result.

SUM adds numeric values. COUNT(*) counts rows. An aggregate without GROUP BY returns one row. SUM over no matching rows is NULL; use COALESCE(SUM(amount),0) when your contract expects zero.

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

Read the example

SELECT SUM(amount) FROM expenses;
Check the expected output
[[15]]

Your challenge

Return the sum of food expenses.

Common trap

Row order is only guaranteed with ORDER BY.

Next lesson: Group related rows