如何找到第3个最高薪水.. [英] how to find 3rd maximum salary..

查看:56
本文介绍了如何找到第3个最高薪水..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当表包含重复数据时如何找到第3个最高工资。

how to find 3rd maximum salary when table contains duuplicate data.

推荐答案

Hi Mukesh,



请从表格中找到以下第3个最高分的查询。





Hi Mukesh ,

Please find the below query for 3 rd highest mark from table.


SELECT
    TOP 1 mark
FROM
    (SELECT DISTINCT TOP 3 mark FROM mark ORDER BY mark DESC) a ORDER BY mark


以下查询将为您提供更多正确答案: -



below query will give you more correct answer:-

select * from (
select dense_rank() over (order by sal desc) as num, * from tablename) a
where num=3


使用2个查询



这可以获得前三名的工资!

Use 2 queries

This gets you the top 3 salaries!
Select top 3 * from Table order by salary





在第二个查询中换行





Wrap that in a second query

Select top 1 *
From (Select top 3 * from Table order by salary)
order by salary desc





使用Row_Number有一个更复杂的解决方案,但上面的工作将完成。



There is a more complex solution using Row_Number but the above will do the job.


这篇关于如何找到第3个最高薪水..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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