一个很简单sql问题
with
t1 as
(
select 'jones' as name,2975 as sal from dual
union all
select 'scott' as name,3000 as sal from dual
union all
select 'ford' as name,3000 as sal from dual
union all
select 'sakl' as name,2500 as sal from dual
union all
select 'wh' as name,1100 as sal from dual
)
select * from t1
以上为数据
问题描述:展示收入排名前三位的员工信息
结果:
1 scott 3000
1 ford 3000
2 jones 2975
3 sakl 2500
求sql
------解决方案-------------------- --1,1,3RANK
SELECT * FROM (
SELECT name,RANK()OVER(ORDER BY SAL DESC) AS RANKSEL FROM T1) WHERE RANKSEL<=3
--1,1,2,3DENSE_RANK
SELECT * FROM (
SELECT name,DENSE_RANK()OVER(ORDER BY SAL DESC) AS RANKSEL FROM T1) WHERE RANKSEL<=3