First, the query will return the nth lower salary value . To return a nthhigher salary value , you must change t.sal <= salto t.sal >= sal.
, , , , . t.sal <= sal ( ) emp. , .
:
Alice | 200
Bob | 100
Charlie | 200
Danielle | 150
Select Distinct sal
From emp
200
100
150
Alice - There are 3 distinct salary values less than or equal to 200
Bob - 1 rows <= 100
Charlie - 3 rows <= 200
Danielle - 2 row <= 150
, ( ):
Bob 1
Danielle 2
Charlie 3
Alice 3
, , , , , emp ( ). I.e., emp t.sal <= sal. , ( As Z):
Select sal
From emp As t
Where &n = (
Select Count(Z.sal)
From (
Select Distinct sal
From emp
) As Z
Where t.sal <= Z.sal
)