0
select * from(select e.*,dense_rank() over(partition by dept_name order by salary desc) as Top_salaried
from employee e) as B where Top_salaried <= 3;

I have the above query that fetches top 3 salary from each dept above is working fine PostgreSQL

when i try to exec the same in oracle it throws error

SQL command not properly ended

Can anyone please help me with this how do i need to modify it in oracle

1 Answers1

0

In Oracle, table aliases don't allow the AS keyword (but column aliases do, such as as top_salaried). So:

SELECT *
  FROM (SELECT e.*,
               DENSE_RANK ()
                  OVER (PARTITION BY dept_name ORDER BY salary DESC)   AS top_salaried
          FROM employee e) b   --> no "as" here
 WHERE top_salaried <= 3;
Littlefoot
  • 131,892
  • 15
  • 35
  • 57