COUNT function is used to count a number of rows. If you want to count only unique elements, you can use DISTINCT to exclude duplicated elements.
Example 1: count a number of employees
SELECT COUNT(*) FROM tbEmpTable;
COUNT(*) |
24 |
Example 2: count numbers of employees by each department.
SELECT deptCD, COUNT(*) FROM tbEmpTable GROUP BY deptCD;
deptCD | COUNT(*) |
100 | 3 |
200 | 10 |
300 | 7 |
400 | 4 |
Example 3: count a number of departments
SELECT COUNT(DISTINCT deptCD) FROM tbEmpTable;
COUNT(DISTINCT deptCD) |
4 |