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
- Sum all coffee sales.
- Count all orders.
- 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_inr | order_count |
|---|---|
| 18720.0 | 24 |
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.
Ravindra Bagale's Tip – मराठी
Aggregate रो डिटेल वगळतो — शहरनिहाय संख्या हवी तर GROUP BY.
Ravindra Bagale's Tip – हिंदी
Aggregate पंक्ति डिटेल छोड़ता है — प्रति शहर संख्या चाहिए तो GROUP BY।