我找不到查询,但我尝试了波纹管查询,但是它不起作用
SELECT DISTINCT(Salary) FROM table ORDER BY Salary DESC LIMIT n,1
如何找到第n个值。
例如:我有7条记录,我希望获得第四高的薪水。
EID-ELOC --ESAL
A001 TNP10 500000
A002 KAP10 700000
A003 TNP20 600000
A004 TNP10 500000
A005 KAP20 800000
A006 KAP10 900000
A007 APP10 700000
答案 0 :(得分:0)
第二薪水(30),例如:
with mytab (salary) as (
select 10 from sysibm.sysdummy1
union all select 10 from sysibm.sysdummy1
union all select 20 from sysibm.sysdummy1
union all select 30 from sysibm.sysdummy1
union all select 30 from sysibm.sysdummy1
union all select 40 from sysibm.sysdummy1
)
select distinct salary
from (
select salary, dense_rank() over (order by salary desc) r_
from mytab
) where r_=2;
答案 1 :(得分:0)
/ *最高* /
with cte as (
select a.* , row_number() over (order by salary desc) rn from mytable a
) select * from cte where rn = 4