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

SQL/MX Functions and Expressions
HP NonStop SQL/MX Reference Manual540440-003
9-33
Examples of COUNT
Nulls
COUNT is evaluated after eliminating all nulls from the one-column table specified by
the operand. If the table has no rows, COUNT returns zero.
COUNT(*) does not eliminate null rows from the table specified in the FROM clause of
the SELECT statement. If all rows in a table are null, COUNT(*) returns the number of
rows in the table.
Examples of COUNT
Count the number of rows in the EMPLOYEE table:
SELECT COUNT (*)
FROM persnl.employee;
(EXPR)
-----------
62
--- 1 row(s) selected.
Count the number of employees who have a job code in the EMPLOYEE table:
SELECT COUNT (jobcode)
FROM persnl.employee;
(EXPR)
-----------
56
--- 1 row(s) selected.
SELECT COUNT(*)
FROM persnl.employee
WHERE jobcode IS NOT NULL;
(EXPR)
-----------
56
--- 1 row(s) selected.
Count the number of distinct departments in the EMPLOYEE table:
SELECT COUNT (DISTINCT deptnum)
FROM persnl.employee;
(EXPR)
-----------
11
--- 1 row(s) selected.