Aggregating Totals with COUNT & SUM
Calculate high-level summary metrics across thousands of rows in a single query.
Why this matters
Managers rarely want a list. They want totals, like how many orders and how much money. COUNT and SUM give you those in one line.
Totals Turn Many Rows Into One
COUNT(*) counts rows. SUM(column) adds up a column. Many rows go in and one summary row comes out.
In real life: A shop owner does not read every receipt at closing time. She wants "how many sales" and "how much money". COUNT and SUM give her those two numbers.
Give Results a Clear Name
Use AS to name a result, like AS total_revenue. Reports and dashboards can then read it easily.
In real life: AS gives the result a clear name, like total_revenue. Without it, the column gets an ugly default name.
Your practice task
Calculate the total number of orders and overall revenue from orders. Name the columns total_orders and total_revenue.
How to do it
- Decide what you need to count and what you need to add up.
- Use one function for the number of orders and one for the money.
- Give each result the name the brief asks for.
- Press Run proof and read the checklist.
Practice it for free in the app. You get instant checks that show what you got right and what to fix. A lesson takes about two minutes and you can try as many times as you like.
Quick reference: Basic Aggregations
Calculates volume and financial aggregates.
SELECT COUNT(*) AS total_count, SUM(val) AS total_val FROM table;
More lessons in this course
- SQL INNER JOIN Explained for BeginnersCombine data from multiple tables using shared primary and foreign key IDs.
- Combining Conditions: AND, OR, IN & LIKECombine several filters in one WHERE clause to find exactly the rows a business question needs.
- Unique Values & AveragesUse DISTINCT, AVG, MIN, and MAX to describe a dataset in a single summary row.