select the id from the table based on highest salary from each dept
table
| Id | dept | salary |
|---|---|---|
| 1 | support | 25000 |
| 2 | support | 20000 |
| 3 | development | 35000 |
| 4 | development | 25000 |
| 5 | development | 30000 |
select Id from table
where salary In (select max(salary) from table group by dept)
If run query like this I am getting output like
| Id |
|---|
| 1 |
| 3 |
| 4 |
I used the ranking window functions and CTE to solve this query
with rank_message as (select id,dept,
ROW_NUMBER() over (partition by dept order by salary desc) as sal
from table S)
select id,dept from rank_message where sal=1