Ravindra BagaleCourses & study guides Track your progress

11. Aggregate Functions: SUM COUNT AVG MIN MAX

11.2 SUM and AVG on Money Columns (₹ $ £ €)

Why. Money totals and averages are daily analyst work across ₹ $ £ €.

What. SUM adds. AVG averages non-NULL values. Keep currency in the column name or filter.

How. Never sum INR and USD in one column without converting.

Steps

  1. SUM and AVG on raja_coffee INR.
  2. SUM by currency on interview_mini sales.
  3. Read units in the alias.

Examples

Example 1 · dataset: raja_coffee

SELECT ROUND(SUM(amount_inr),2) AS total_inr,
       ROUND(AVG(amount_inr),2) AS avg_inr
FROM orders;

Output

total_inravg_inr
18720.0780.0

Meaning. Total and average order value in INR.

Example 2 · dataset: interview_mini

SELECT currency, ROUND(SUM(amount),2) AS total
FROM sales
GROUP BY currency
ORDER BY currency;

Output

currencytotal
EUR475.0
GBP295.0
INR4000.0
USD470.0

Meaning. Separate totals per currency — do not mix.

Ravindra Bagale's Tip

ROUND(…,2) helps money display; still store full precision when you can.