Icon COUNT

Returns the count of a given expression for all selected rows, or the count of all selected rows.

Syntax
COUNT(*|[DISTINCT] <Expression>)

<Expression> =

Type of:

CHARACTER|CHAR
CHARACTER VARYING|VARCHAR
GUID
BYTE
BYTE VARYING|VARBYTE
BINARY LARGE OBJECT|BLOB
CHARACTER LARGE OBJECT|CLOB
BOOLEAN|BOOL
SMALLINT
INTEGER|INT
BIGINT
FLOAT
DECIMAL|NUMERIC
DATE
TIME
TIMESTAMP
INTERVAL YEAR
INTERVAL YEAR TO MONTH
INTERVAL MONTH
INTERVAL DAY
INTERVAL DAY TO HOUR
INTERVAL DAY TO MINUTE
INTERVAL DAY TO SECOND
INTERVAL DAY TO MSECOND
INTERVAL HOUR
INTERVAL HOUR TO MINUTE
INTERVAL HOUR TO SECOND
INTERVAL HOUR TO MSECOND
INTERVAL MINUTE
INTERVAL MINUTE TO SECOND
INTERVAL MINUTE TO MSECOND
INTERVAL SECOND
INTERVAL SECOND TO MSECOND
INTERVAL MSECOND

Returns
INTEGER

Usage
The COUNT function returns the count of a given expression for all selected rows, or the count of all selected rows. The selected rows can be grouped into logical sub-sets by using the GROUP BY clause of the SELECT statement. Any time the counted expression is NULL, it is excluded from the count calculation. Use of the asterisk (*) instead of an expression indicates that you want the function to count all selected rows, irrespective of any given expression.

Use the DISTINCT clause to specify that the count calculation will only use distinct values when calculating the result.

Examples
SELECT CAST(TransDateTime AS DATE) AS TransDate,
COUNT(*) AS NumTransactions
FROM Transactions
GROUP BY TransDate

SQL 2003 Standard Deviations
This function deviates from the SQL 2003 standard in the following ways:

DeviationDetails
None
Image