本文介绍了我想在单个sql语句中找到第二个最高工资和第三个最低工资。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
T_ID T_NAME BPS_GRADE SALARY
1 IMRAN 17 30000
2 AHMAD 18 35000
3 KAMRAAN 17 32000
4 ASIF 19 40000
5 TOFEEQ 18 33000
T_ID T_NAME BPS_GRADE SALARY
1 IMRAN 17 30000
2 AHMAD 18 35000
3 KAMRAAN 17 32000
4 ASIF 19 40000
5 TOFEEQ 18 33000
推荐答案
SELECT RowNo, T_ID, T_NAME, BPS_GRADE, SALARY
FROM (
SELECT T_ID, T_NAME, BPS_GRADE, SALARY, ROW_NUMBER OVER(ORDER BY SALARY DESC) AS RowNo
FROM YourTableName
) AS T
WHERE RowNo IN (2,3)
请参阅 []。
SELECT MAX(ESAL)AS SECONDMAXSAL FROM EMP1 WHERE ESAL NOT IN(SELECT MAX(ESAL) FROM EMP1)
- 找到第三季度的佣金
--FIND THIRDMAXSAL SALARY
SELECT MIN(ESAL)AS THIRDMAXSAL FROM EMP1 WHERE ESAL IN(SELECT TOP 3 (ESAL) FROM EMP1 ORDER BY ESAL DESC)
这篇关于我想在单个sql语句中找到第二个最高工资和第三个最低工资。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!