GROUP BY can be combined with AVG to calculate the average of a numeric column for each group. This allows analysts to compare typical values across different categories.
Overall averages can hide important differences between groups. Group-level averages provide a clearer view of performance across departments, regions, products, or customers.
An HR analyst wants to compare average salary across departments. GROUP BY Department with AVG(Salary) can provide the required analysis.
SELECT
Department,
AVG(Salary) AS AverageSalary
FROM Employees
GROUP BY Department;
GROUP BY with AVG is useful for salary analysis, average order value, regional performance, product pricing, customer spending, and operational metrics.
- AVG calculates an average.
- GROUP BY calculates the average separately for each group.
- AVG works with numeric expressions.
- NULL values are generally ignored.
- Group-level averages are useful for comparisons.
How do you calculate average salary by department?
Use GROUP BY Department together with AVG(Salary).
Why use GROUP BY with AVG?
It allows the average to be calculated separately for each group.