COUNT Function [Aggregate]

Counts the number of rows in a group, depending on the specified parameters.

Syntax

COUNT* | expression | DISTINCT column-name )

Parameters

Parameter

Description

*

Returns the number of rows in each group.

expression

Returns the number of rows in each group where expression is not the NULL value.

DISTINCT column-name

Returns the number of different values in column-name. Rows where the value is the NULL value are not included in the count.

Note: When the query results are displayed, the * is not displayed in the column header, and appears as:
Count()

Returns

INT

Example

Returns each unique city, and the number of rows with that city value:

SELECT city , Count(*)
FROM Employees
GROUP BY city

Standards and Compatibility

  • SQL—ISO/ANSI SQL compliant.

  • Sybase—Compatible with Adaptive Server Enterprise.

Related concepts
Windowing Aggregate Function Usage
Related reference
AVG Function [Aggregate]
SUM Function [Aggregate]