Ravindra BagaleCourses & study guides Track your progress

11. Aggregate Functions: SUM COUNT AVG MIN MAX

11.1 What an Aggregate Does (Many Rows → One Number)

Why. Managers ask for one number, not 10,000 rows.

What. An aggregate collapses many rows into one value: SUM, COUNT, AVG, MIN, MAX.

How. SELECT SUM(amount_inr) FROM orders;

Steps

  1. Sum all coffee sales.
  2. Count all orders.
  3. Feel: many rows → one cell.

Examples

Example 1 · dataset: raja_coffee

SELECT SUM(amount_inr) AS total_sales_inr,
       COUNT(*) AS order_count
FROM orders;

Output

total_sales_inrorder_count
18720.024

Meaning. One total and one count for the whole table.

Ravindra Bagale's Tip

Aggregates ignore row detail — use GROUP BY when you need one number per city.