RSS Feed

SQL Count

SQL Count

Counting total number of records in a table:

SELECT COUNT(*) FROM table_name

The below query returns the number of values (NULL values will not be counted) of the specified column:

SELECT COUNT(column_name) FROM table-name

Counting the number of distinct values of the specified column:

SELECT COUNT(DISTINCT column-name) FROM table-name

The following SQL statement would return the name of the department and the number of employees (in the associated department) that make over $12,000 / year.

SELECT department, COUNT(*) as "Employee COunt - Number of employees"
FROM employees
WHERE salary > 12000
GROUP BY department;

Some more useful stuff on SQL Count

SQL COUNT( NULLIF( .. ) ) Is Totally Awesome
SQL COUNT NULLIF

Counting the number of columns in a table
SQL Server - Counting the number of columns in a table

No comments:

Post a Comment