标签:des io ar 数据 art sp on c sql
Oracle分析函数
--row_number():连续不重复 1234567
--rank():跳跃可重复 12333678
--dense_rank():连续可重复 12333456
row_number() over(partition by deptno order by sal desc)
over( partition by [分区字段,可以有多个] order by [一个或多个字段])
笔试题题目如下:
题目如下:
请用一条sql语句查询出scott.emp表中每个部门工资前三位的数据,显示结果如下:
DEPTNO SAL1 SAL2 SAL3
------ ---------- ---------- -------------------------------------
10 5000 2450 1300
20 3000 2975 1100
30 2850 1600 1500
select deptno ,max(sal) 第一名 ,max(decode(t ,2 ,sal)) 第二名 ,min(sal) 第三名 from (select sal ,deptno ,t from (select empno ,ename ,sal ,row_number() over(partition by deptno order by sal desc) t ,deptno from emp) e where e.t <= 3) group by deptno;
标签:des io ar 数据 art sp on c sql
原文地址:http://my.oschina.net/KingPan/blog/306840