SQL/MX 2.x Reference Manual (H06.04+)

SQL/MX Functions and Expressions
HP NonStop SQL/MX Reference Manual540440-003
9-15
Examples of AVG
Examples of AVG
Return the average value of the SALARY column:
SELECT AVG (salary)
FROM persnl.employee;
(EXPR)
---------------------
49441.52
--- 1 row(s) selected.
Return the average value of the set of unique SALARY values:
SELECT AVG(DISTINCT salary) AS Avg_Distinct_Salary
FROM persnl.employee;
AVG_DISTINCT_SALARY
---------------------
53609.89
--- 1 row(s) selected.
Return the average salary by department:
SELECT deptnum, AVG (salary) AS "AVERAGE SALARY"
FROM persnl.employee
WHERE deptnum < 3000
GROUP BY deptnum;
Dept/Num "AVERAGE SALARY"
-------- ---------------------
1000 52000.17
2000 50000.10
1500 41250.00
2500 37000.00
--- 4 row(s) selected.