最低和最高工资显示 [英] lowest and highest salaries display

查看:81
本文介绍了最低和最高工资显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从员工表中获得前5名薪水和第二高薪但是它也显示了我最低薪水



查看此图片ssalry栏

工资栏 [ ^ ]





,这是输出



输出 [ ^ ]





这是我尝试的查询



  SELECT  MAX(薪水) FROM 员工
WHERE 薪资 NOT IN SELECT MAX(薪水) FROM 员工

选择 top 5 salary 来自员工;

解决方案

请试试这个:



获得第n个最高薪水:



  SELECT   TOP   1  salary 
FROM
SELECT DISTINCT TOP n薪水
FROM 员工
ORDER BY salary DESC )a
ORDER BY 薪水





以上,替换n到2&你将获得第二高的薪水。



前5名工资单请尝试:



  SELECT   DISTINCT   TOP   5 薪水
FROM 员工
ORDER BY salary DESC







如需更多帮助,请参阅以下链接&根据您的需要自定义查询:



SQL SERVER–找到员工的第N个最高工资–查询以检索第N个最大值–与Pinal Dave一起探索SQL权威 [ ^ ]


我不确定我是不是了解你想要什么,但我会尝试尝试。您是否正在寻找桌上的前五名薪水?如果是,这不适合吗?



 选择  distinct   top   5  salary 来自员工订单  salary 降序 


i try to get top 5 salary and second highest salary from employees table but it shows me also lowest salaries

check this picture ssalry column
salary column[^]


and this is the output

output[^]


this is the queries which i try

SELECT MAX(Salary) FROM Employees
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employees )

select top 5 salary from Employees;

解决方案

Please try this:

To get nth highest salary:

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employees
ORDER BY salary DESC) a
ORDER BY salary



in above, replace n to 2 & you will get 2nd highest salary as you required.

And for top 5 salary list please try :

SELECT DISTINCT TOP 5 salary
FROM employees
ORDER BY salary DESC




For more help please see the link below & customize the query as per your need:

SQL SERVER – Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value – Journey to SQL Authority with Pinal Dave[^]


I am not really sure if I understand what you want here but I will try and attempt. Are you looking for top 5 salaries from the table? If yes, doesn't this fit?

select distinct top 5 salary from employees order by salary desc


这篇关于最低和最高工资显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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