COUNT – Count the number of records – Aggregate Functions

COUNT function can count the number of records(rows). If you use DISTINCT, you can eliminate duplicated data and count the number of rows.

example: to count the number of employees.

SELECT COUNT(*) FROM tbEmpTable;

COUNT(*)
----------------------
24

example: count the number of employees in each department.

SELECT deptCD, COUNT(*) FROM tbEmpTable
GROUP BY deptCD;

deptCD,    COUNT(*)
----------------------------------
100               3
200               10
300               7
400               4

example: count the number of department using DISTINCT.

SELECT COUNT(DISTINCT deptCD) FROM tbEmpTable

COUNT(DISTINCT deptCD)
--------------------------------
4

Posted in Aggregate Functions