Description

The SQL Aggregate Functions can be used to perform calculations on a set of values and return a single value, based on the type of functions.

  • These can be used only with a SELECT statement.
  • These perform calculations on a set of values and return a single value.

See aggregate functions for more details.

Let's look at an example SELECT statement with a COUNT() function, which returns the number of rows with non-NULL values on the specific column.

Table Date

employee_id employee_name gender birth_date hire_date salary
1 Robin Hood M 1990-10-10 2010-10-15 25000
2 Tony Blank M 1982-08-07 2010-01-05 89000
3 Andrew Russel M 1998-05-04 2012-02-20 28000
4 James Cooper NULL 2000-10-20 2015-05-10 45000
5 Rose Cutler F 1985-08-08 2015-06-21 65000

Example

The below SELECT statement returns the number of rows in a result set, considering only the non-NULL values on the specified column.

Run this on IDE

SELECT COUNT(gender) FROM employees;

After successful execution, the output contains the below data.

COUNT(gender)
4

Overall

We now understood the usage of the COUNT() function on a SELECT statement.

Related Links