如何在sql查询中获得前5个薪资数据 [英] How to get top 5 salary data in sql query

查看:151
本文介绍了如何在sql查询中获得前5个薪资数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一张带薪水栏的表格



现在我想要一个单一的查询,它会返回所有前5名薪水的员工。



如果33名员工有30000工资,那么一切都应该来。



提前致谢

解决方案

这应该有效。我在我的机器上测试了它



  SELECT  * 
FROM table
WHERE

sal IN

SELECT < span class =code-keyword> TOP ( 5 )sal
FROM as table1
GROUP BY sal
ORDER BY sal DESC





sal =工资栏

table = table name


你好肯定会工作:

 < span class =code-keyword>选择 * 来自员工其中薪水 选择 不同  top   5  salary 来自员工订单  by  salary  desc 





SELECT TOP 5 WITH TIES名称,工资来自tlevel ORDER BY Salary desc


  with 结果 as  

select dense_rank() over order by salary) as ' Top薪水',* 来自 名称
选择 * 来自结果其中​​ TopSalary 介于 1 5


Suppose i have a table with salary column

now i want a single query which returns all the employees who have top 5 salaries.

If 33 employees have 30000 salary then all should come.

Thanks in advance

解决方案

This should work. I have tested it on my machine

SELECT *
FROM table
WHERE 
(
  sal IN 
  (
    SELECT TOP (5) sal
    FROM table as table1
    GROUP BY sal
    ORDER BY sal DESC
  )
)



sal = salary column
table = table name


Hi It will definatly work:

select  * from employee where salary in (select distinct top 5 salary from employee order by salary desc)



SELECT TOP 5 WITH TIES Name, Salary FROM tlevel ORDER BY Salary desc


with Result as
(
   select dense_rank () over (order by salary) as 'TopSalary',* from table name
) select * from Result where TopSalary between 1 and 5


这篇关于如何在sql查询中获得前5个薪资数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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