How to find a third lowest salary without RANK or TOP function

Database
KVB
N/A

How to find a third lowest salary without RANK or TOP function

Hi

I need to find the third lowest salary without using RANK or TOP function?

3 REPLIES

Re: How to find a third lowest salary without RANK or TOP function

You can find it using the following co-related subquery:

SELECT * FROM Employee E1 WHERE n-1 = 
(SELECT COUNT(DISTINCT Salary_amount) FROM Employee E2 WHERE E1.Salary_amount > E2.Salary_Amount)

Where n is the level you want to find. for example in your case, replace n with 3.

Khurram
KVB
N/A

Re: How to find a third lowest salary without RANK or TOP function

Yes.Got it.Thank you.

N/A

Re: How to find a third lowest salary without RANK or TOP function

Hi,

did you try with a window function ?

-- Partition by Department

qualify row_number() over(partition by Department order by Salary_Amount) < n

-- NO Partition at all

qualify row_number() over(order by Salary_Amount) < n

Pierre