TryBench
Data Analysis & SQL · Foundation lesson 4 of 19

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

  1. Decide what you need to count and what you need to add up.
  2. Use one function for the number of orders and one for the money.
  3. Give each result the name the brief asks for.
  4. 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;

Practice this lesson free

More lessons in this course

See all 19 lessons in Data Analysis & SQL