打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Find Nth highest record from table
In interview you can faced question like to give solution(query) for find Nth highest Record/number/salary from given employee table.

TO find out 3rd highest salary from table

--Find 3rd highest salary
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 3 salary
FROM tblSalary
ORDER BY salary DESC) S
ORDER BY salary

General form to find to Nth highest salary from table

--Find Nth highest salary
SELECT TOP 1 salary FROM (
SELECT DISTINCT TOP N salary FROM tblSalary ORDER BY salary DESC) S
ORDER BY salary

There are many solution to solve to this but above solution is easiest.
Take other possible solution,

SELECT MIN(salary) FROM tblSalary WHERE salary IN
(SELECT DISTINCT TOP 3 salary FROM tblSalary ORDER BY salary DESC)

--or--

SELECT MIN(salary) FROM
(SELECT DISTINCT TOP 3 salary FROM tblSalary ORDER BY salary DESC) S
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
LeetCode-Algorithms #002 Add Two Numbers, Database #176 Second Highest Salary
SQL今日一题(7):去重
在sql中删除重复记录(多种方法)
SQL: COUNT Function
SQL常用命令使用方法和sql基本语句
数据库(二)自动增长列,添加表数据,修改数据,删除数据,where条件,%通配符,is,查询数据(查询全表,指定列查询,排序查询),聚合查询(平均、最大、最小、行数、求和)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服