Tuesday, 22 July 2014

How to calculate Nth highest/lowest salaries without using Analytical functions

Nth Highest Salary:

SELECT EMPNO,ENAME,SAL FROM EMP X WHERE &N =

(SELECT COUNT(DISTINCT SAL) FROM EMP WHERE SAL >=X.SAL);


Nth Lowest Salary:

SELECT EMPNO,ENAME,SAL FROM EMP X WHERE &N = 
(SELECT COUNT(DISTINCT SAL) FROM EMP WHERE SAL <=X.SAL);


No comments:

Post a Comment