每个部门的前两个薪水 [英] First two salaries in each department

查看:83
本文介绍了每个部门的前两个薪水的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表叫Departments,由一个叫薪金的列组成.现在,我想获取每个部门中最高的两个薪水的所有详细信息.我们应该如何开发产生所需输出的查询? Top-N分析将为您提供一个整体,但不能为每个部门提供.我想要每个部门的前两名.

I have a table called departments which consists of a column called salary. Now I want to have all the details of the highest two salaries in each department. How should we develop a query which yields the required output? Top-N analysis will give it as a whole but not for each department. I want the top two in each department.

推荐答案

我知道您在Oracle中要求这样做.我不能在那帮你.

I realize you asked for this in Oracle. I can't help you there.

但是,也许如果您在MSSQL/TSQL中看到了解决方案,它将有所帮助吗?

But, perhaps if you see the solution in MSSQL/TSQL it will help?

select 
     d.Salary
    ,d.Department
from
(
    select 
         r.Salary
        ,r.Department
        ,row_number() over(
            partition by r.Department
            order by r.Salary desc) as RowNumber
    from HumanResources as r
) as d
where d.RowNumber < 3

祝你好运!

这篇关于每个部门的前两个薪水的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆