AVG function is used to calculate an average value from a selected field.
Example1: Calculate an average value of employees’ salary.
SELECT AVG(salary) FROM tbSalaryTable;
AVG(salary) |
254000 |
Example2: Calculate an average value of salary by each department.
SELECT deptCD, AVG(salary) FROM tbSalaryTable GROUP BY deptCD;
deptCD | AVG(salary) |
100 | 150000 |
200 | 203090 |
300 | 403200 |
400 | 305420 |