over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用。常用作排序、获得行号等。
如:1.在部门10,20,30中进行部门内薪水排名的sql写法为:
其中的over与rank联用,partition by 感觉像group by,指定分组的依据,order by指定排序的字段。
2.使用行号的一个应用
如:1.在部门10,20,30中进行部门内薪水排名的sql写法为:
select deptno ,ename,empno ,sal ,rank() over(partition by deptno order by sal desc) from emp;
其中的over与rank联用,partition by 感觉像group by,指定分组的依据,order by指定排序的字段。
2.使用行号的一个应用
select ename from (select row_number() over (order by ename) rn,ename
from emp) where mod(rn,2)=1;