0

I'm using the HR@orcl learning account from oracle.
-----------------------------------------------------
and I have the following question :
Create a an SQL query to display the department, the number of employees for that department based on their salary, and the total number of employees for that department, giving each column an appropriate heading.
the salary should be divided like : Less Than 5000,More 5000 And Less 10000 etc .....
-----------------------------------------------------

I tried to use ( Case ) with ( Group By ) but i failed also I tried to use subquery or aggregate functions in the case but it didn't work ...

any help or hint how to solve this .

ex :

select department_id,count(*),case(.....) from employees group by department_id;

it gave errors . any ideas how to solve it .

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jbisono
0

You need something like this

SELECT COUNT(ID) AS EmploCount, DEPARTMENT_ID, Salary
FROM (SELECT     ID, DEPARTMENT_ID, CASE WHEN salary < 5000 THEN 'Less than 5000' ELSE CASE WHEN salary BETWEEN 5000 AND 10000 THEN 'More thant 5000 and less than 10000' ELSE 'More than 10000' END END AS Salary 
FROM Employee) AS derivedtbl_1
GROUP BY DEPARTMENT_ID, Salary
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.