您好,登录后才能下订单哦!
这篇“SQL搜索前三名的方法是什么”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“SQL搜索前三名的方法是什么”文章吧。
具体数据和SQL是这样的
WITH Employee AS(
SELECT 1 Id, 'joe' Name,70000 SALARY,1 DepartmentId FROM DUAL UNION ALL
SELECT 2 Id, 'Henry' Name,80000 SALARY,2 DepartmentId FROM DUAL UNION ALL
SELECT 3 Id, 'Sam' Name,60000 SALARY,2 DepartmentId FROM DUAL UNION ALL
SELECT 4 Id, 'Max' Name,90000 SALARY,1 DepartmentId FROM DUAL UNION ALL
SELECT 5 Id, 'Janet' Name,69000 SALARY,1 DepartmentId FROM DUAL UNION ALL
SELECT 6 Id, 'Randy' Name,85000 SALARY,1 DepartmentId FROM DUAL
),
Department AS (
SELECT 1 Id, 'IT' Name FROM DUAL UNION ALL
SELECT 2 Id, 'Sales' Name FROM DUAL
)
SELECT T1.Name,T2.*
FROM
Department T1
,Employee T2
WHERE T1.Id= T2.DepartmentId
AND 3>
(
SELECT COUNT(distinct T3.SALARY) RN
FROM Employee T3
WHERE T2.DepartmentId = T3.DepartmentId
AND T2.SALARY < T3.SALARY
)
ORDER BY T2.DEPARTMENTID,T2.SALARY
以上就是关于“SQL搜索前三名的方法是什么”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。