-->

Spiga

Nth Highest Salary

Using This Query You Can Find 'n' th highest salary:


Create Table Emp(Empno varchar2(6),Sal number);

insert into Emp(Empno,Sal) Values ('000100',4579);
insert into Emp(Empno,Sal) Values ('000101',5879);
insert into Emp(Empno,Sal) Values ('000102',8839);
insert into Emp(Empno,Sal) Values ('000104',2849);

Commit;

SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);


For Eg:-

Enter value for n: 2

SAL
---------
5879

There was an error in this gadget