Example
Employees table
ID | MANAGER_ID | SAL | DEPT_ID |
---|---|---|---|
1 | 8 | 3000 | 20 |
2 | 8 | 3000 | 20 |
3 | 1 | 800 | 20 |
4 | 7 | 950 | 30 |
5 | 2 | 1100 | 20 |
6 | 9 | 1300 | 10 |
7 | 10 | 2850 | 30 |
8 | 10 | 2975 | 20 |
9 | 10 | 2450 | 10 |
10 | NULL | 5000 | 10 |
Count the number of employees group by department
SELECT COUNT(ID) EMP_NO, DEPT_ID
FROM EMPLOYEES
WHERE MANAGER_ID IS NOT NULL
GROUP BY DEPT_ID;
Results
EMP_NO | DEPT_ID |
---|---|
2 | 10 |
5 | 20 |
2 | 30 |
Select the sum of salary group by department
SELECT DEPT_ID, SUM(SAL) SAL_SUM
FROM EMPLOYEES
GROUP BY DEPT_ID;
Results
DEPT_ID | SAL_SUM |
---|---|
10 | 8750.00 |
20 | 10875.00 |
30 | 3800.00 |