Neoview SQL Reference Manual (R2.4)
COUNT Function
The COUNT function 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.
COUNT {(*) | ([ALL | DISTINCT] expression)}
COUNT (*)
returns the number of rows in the table specified in the FROM clause of the SELECT statement
that contains COUNT (*). If the result table is empty (that is, no rows are returned by the
query) COUNT (*) returns zero.
ALL | DISTINCT
returns the number of all rows or the number of distinct rows in the one-column table derived
from the evaluation of expression. The default option is ALL, which causes duplicate
values to be included. If you specify DISTINCT, duplicate values are eliminated before the
COUNT function is applied.
expression
specifies a value expression that determines the values to count. The expression cannot
contain an aggregate function or a subquery. The DISTINCT clause specifies that the COUNT
function operates on distinct values from the one-column table derived from the evaluation
of expression. See “Expressions” (page 240).
Considerations for COUNT
Operands of the Expression
The operand of COUNT is either * or an expression that includes columns from the result table
specified by the SELECT statement that contains COUNT. However, the expression cannot
include an aggregate function or a subquery. These expressions are valid:
COUNT (*)
COUNT (DISTINCT JOBCODE)
COUNT (UNIT_PRICE * QTY_ORDERED)
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)
350 SQL Functions and Expressions