久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

根據表格數據找到每個部門的第三個最高工資

Find the 3rd Maximum Salary for each department based on table data(根據表格數據找到每個部門的第三個最高工資)
本文介紹了根據表格數據找到每個部門的第三個最高工資的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要在中找出每個部門員工的第三個最高工資.如果不存在第三個最高工資,則顯示第二個最高工資.如果不存在第二個最高工資,則找到最高工資.如何在sql-server中實現這個結果?

I need to find out the 3rd maximum salary for an employee for each department in a table. if no 3rd maximum salary exists then display 2nd maximum salary. if no 2nd maximum salary exist then find the highest salary. How to achieve this result in sql-server?

table 結構如下

create table employee1(empid int, empname varchar(10), deptid int, salary money)

insert into employee1
select 1,'a',1, 1000
union
select 1,'b',1, 1200 
union
select 1,'c',1, 1500 
union
select 1,'c',1, 15700 
union
select 1,'d',2, 1000 
union
select 1,'e',2, 1200 
union
select 1,'g',3, 1500 

我已經嘗試了使用 row_number 函數獲取每個類別最高工資的常用方法.

I have tried the common way of getting the maximum salary for each category using row_number function.

;with cte
as
( 
select ROW_NUMBER( ) over( partition by deptid order by salary) as id, * from employee1 
)
select * from cte

推薦答案

Select EmpID,empname,deptid,salary
 From (
Select *
      ,RN  = Row_Number() over (Partition By deptid Order By Salary)
      ,Cnt = sum(1) over (Partition By deptid)
 From  employee1
      ) A
 Where RN = case when Cnt<3 then Cnt else 3 end

退貨

這篇關于根據表格數據找到每個部門的第三個最高工資的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 99只有精品 | 99久久精品国产毛片 | 免费亚洲婷婷 | 久久久久久国产精品免费免费狐狸 | 国产成视频在线观看 | 蜜桃av一区二区三区 | 黄色欧美大片 | 天天综合久久 | 免费观看a级毛片在线播放 黄网站免费入口 | 激情毛片 | 日日夜夜草 | 欧美一区二区三区 | 欧美成人猛片aaaaaaa | 羞羞视频在线观免费观看 | 日本福利在线观看 | 欧美乱做爰xxxⅹ久久久 | 黑人巨大精品 | 国产在线对白 | 国产小视频在线看 | 亚洲激情网站 | 精品亚洲一区二区三区四区五区 | 亚洲欧美激情网 | 九九热这里 | 日韩欧美在线观看 | 亚洲 欧美 综合 | 三级在线视频 | 麻豆精品国产免费 | 国产精品资源在线 | av手机在线免费观看 | 91视频88av| 欧美国产日韩一区二区三区 | 综合色在线 | 成人激情视频 | 九九热在线免费视频 | 国产精品精品久久久 | 99亚洲国产精品 | 亚洲码欧美码一区二区三区 | 欧美日韩精品一区二区三区视频 | 在线一区 | 久久99精品久久久久久国产越南 | 亚洲视频免费在线观看 |