Ravindra BagaleCourses & study guides Track your progress

29. SQL for Excel Users (Term Map + Side-by-Side)

29.2 GROUP BY = PivotTable / GROUPBY

Why. PivotTable rows/columns/values ≈ GROUP BY + aggregates.

What. Put city on Rows, Sum of amount on Values → GROUP BY city, SUM(amount).

How. Build the SQL pivot twin for sales by city.

Steps

  1. Picture the Pivot.
  2. Write GROUP BY.
  3. Match totals to Excel if you export CSV.

Examples

Example 1 · dataset: raja_coffee

SELECT city, ROUND(SUM(amount_inr),2) AS sales_inr
FROM orders
GROUP BY city
ORDER BY sales_inr DESC;

Output

citysales_inr
Pune9170.0
Mumbai2490.0
Kolhapur2410.0
Nashik2320.0
Goa1600.0
Solapur730.0

Meaning. Pivot twin in SQL.

Ravindra Bagale's Tip

Excel GROUPBY function (newer Excel) is even closer to SQL GROUP BY wording.