Write a query to display maximum salary

Solution 1:

select sal  from  (select sal from emp order by sal desc) where rownum=1; 

 

Solution 2 

select sal from  (select sal, rank() over(order by sal desc) r from emp) where r=1; 

 

Solution 3 

select sal from  (select sal,rank() over(order by sal desc) r from emp) where r=1;

 

Solution 4

select sal from emp order by sal desc  fetch first 1 row only;

 

Solution 5

select sal from emp  order by sal desc  offset(2-1) row fetch first 1 row only;

 

Solution 6

select * from emp a where 1=(select count(*) c from emp b where b.sal>=a.sal);

 

Solution 7

select * from emp a, lateral(select * from (select count(*) c from emp b where b.sal>=a.sal)where c=1);

 

Solution 8

select sal from empwhere sal>all(select sal-1 from emp);

 

No comments:

Post a Comment