SQL/MP Reference Manual

HP NonStop SQL/MP Reference Manual523352-013
C-130
COUNT Function
COUNT Function
COUNT is a function that counts the number of rows that result from a query or the
number of rows that contain a distinct value in a specific column.
The result of COUNT is data type LARGEINT. The result can never be null.
*
specifies that COUNT should not exclude null values from the aggregate set. If the
set is empty, COUNT returns zero.
DISTINCT column-name
specifies a set of distinct column values from each row of the result table to
determine COUNT. The column cannot be a column from a view that corresponds
to an expression in the view definition.
Duplicate rows are eliminated only if you specify DISTINCT; otherwise, all rows are
included whether or not you specify ALL.
If you specify DISTINCT in more than one COUNT function in the same statement,
the functions must refer the same column.
Specifying DISTINCT with the COUNT function places no restrictions on the use of
DISTINCT with AVG, SUM, MAX, or MIN.
Considerations—COUNT
COUNT is evaluated after eliminating all null values from the aggregate set, unless
you specify an asterisk (*). If the set is empty, COUNT returns zero.
Example—COUNT
This example counts the number of distinct departments:
>> SELECT COUNT (DISTINCT DEPTNUM) FROM PERSNL.EMPLOYEE;
(EXPR)
--------------------
11
--- 1 row(s) selected.
>>
COUNT { ( * ) }
{ (DISTINCT column-name) }