打開sqldeveloper
----新建連接----
----新建會話----
----新建會話級臨時表----
select * from emp;
----新建中間表 再查找----
with bt as (select emp.*
,rank() over(partition by deptno order by sal desc) rank from emp)
select * from bt where rank<=3;
----函數-----
–聚合函數–
sum()
avg()
count()
max()
min()
–分析函數–
排名函數
rank() over(partition by 字段 order by 字段)
row_number over(partition by 字段 order by 字段)
dense_rank() over(partition by 字段 order by 字段)
遷移函數
lead() 上移
select ename 姓名
,round((lead(sal,2) over(order by hiredate) -sal)/sal,3)*100||'%' 環比 from emp;
lag() 下移
聚合分析函數
sum(字段) over(order by 字段)
select ename 姓名
,sal 工資
,sum(sal) over(order by hiredate) 累計工資 from emp;
avg(字段) over(order by 字段)
count(字段) over(order by 字段)
max(字段) over(order by 字段)
min(字段) over(order by 字段)
下一篇:半連接-相關子查詢