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 .

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.