The AVG()
function in MySQL calculates the average (mean) value of a numeric column. It sums all non-NULL values and divides by the count of those values.
AVG(column_name)
Works only on numeric columns (INT, FLOAT, DECIMAL, etc.). NULLs are ignored.
-- Average salary of all employees SELECT AVG(salary) AS avg_salary FROM employees; -- Average order total SELECT AVG(order_total) AS avg_order FROM orders; -- Average salary in 'Sales' department SELECT AVG(salary) AS avg_sales_salary FROM employees WHERE department = 'Sales';
WHERE
to average a subset of rows.GROUP BY
for per-group averages.-- Average salary by department SELECT department, AVG(salary) AS avg_salary FROM employees GROUP BY department;
This query shows the average salary for each department, giving insights into compensation distribution.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!