Learn SQL Lesson

COUNT and SUM Together

Once you understand single aggregates, the next step is combining them. SQL lets you calculate several summaries in the same query.

For example:

SELECT COUNT(*) AS sale_count, SUM(amount) AS total_amount
FROM sales
WHERE region = 'West'

This is very common in reporting and dashboards because one query can return multiple useful summary values at once.

Practice challenge

For the West region, return the number of sales as sale_count and the total amount as total_amount.

Open interactive editor