如何使用递归CTE获得第N个最高薪水 [英] How to get the Nth highest salary using recursive CTE
本文介绍了如何使用递归CTE获得第N个最高薪水的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
你能否告诉我如何使用递归CTE获得第N个最高工资?
谢谢
Srikanth
解决方案
您不需要递归CTE:
ordered_salary as
(
SELECT 名称,薪水,ROW_NUMBER() OVER ( ORDER BY salary DESC )rn
FROM salary_table
)
选择名称,工资
来自 ordered_salary
其中 rn = 5
Hi Guys,
Can any of you tell me how to get the Nth highest salary using recursive CTE?
Thanks
Srikanth
解决方案
You don't need recursive CTE for that:
with ordered_salary as ( SELECT name, salary, ROW_NUMBER() OVER(ORDER BY salary DESC) rn FROM salary_table ) select name, salary from ordered_salary where rn = 5
这篇关于如何使用递归CTE获得第N个最高薪水的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文