4. WHERE: Keep Only the Rows You Need
4.1 Why WHERE Matters (Filter Before You Aggregate)
Why. Totals on the wrong rows mislead managers.
What. WHERE keeps only rows that match a condition — before you sum or average.
How. SELECT … FROM … WHERE condition;
Steps
- State the filter in words (city is Pune).
- Write WHERE city = 'Pune'.
- Then aggregate in later chapters.
Examples
Example 1 · dataset: raja_coffee
SELECT order_id, city, amount_inr
FROM orders
WHERE city = 'Pune'
LIMIT 5;Output
| order_id | city | amount_inr |
|---|---|---|
| 1001 | Pune | 840.0 |
| 1004 | Pune | 1050.0 |
| 1006 | Pune | 890.0 |
| 1009 | Pune | 700.0 |
| 1013 | Pune | 1680.0 |
Meaning. Only Pune rows — filter before any total.
Ravindra Bagale's Tip
Filter first, aggregate second — muscle memory for clean reports.
Ravindra Bagale's Tip – मराठी
आधी फिल्टर, नंतर aggregate — स्वच्छ रिपोर्टची सवय.
Ravindra Bagale's Tip – हिंदी
पहले फ़िल्टर, फिर aggregate — साफ़ रिपोर्ट की आदत।