Ravindra BagaleCourses & study guides Track your progress

12. GROUP BY: One Row Per Group

12.4 How to Alias Aggregates Clearly for Reports

Why. Ugly aggregate headers confuse Excel exports and Power BI.

What. Alias every aggregate: SUM(amount_inr) AS sales_inr.

How. Name like a report column, not like a formula dump.

Steps

  1. Rewrite a GROUP BY with clear aliases.
  2. Prefer sales_inr over SUM(amount_inr).
  3. Keep units in the name.

Examples

Example 1 · dataset: raja_coffee

SELECT city AS store_city,
       COUNT(*) AS order_count,
       ROUND(SUM(amount_inr),2) AS sales_inr,
       ROUND(AVG(amount_inr),2) AS avg_order_inr
FROM orders
GROUP BY city
ORDER BY sales_inr DESC;

Output

store_cityorder_countsales_inravg_order_inr
Pune109170.0917.0
Mumbai32490.0830.0
Kolhapur32410.0803.33
Nashik32320.0773.33
Goa31600.0533.33
Solapur2730.0365.0

Meaning. Report-ready headers.

Ravindra Bagale's Tip

Aliases travel into CSV exports — choose names managers understand.