oracle复杂查询是sql
一、over()分析函数
分组查前几条:select * from test t where (select count(*) from test a where t.type=a.type and t.scope>a.scope)<2;
--rank()/dense_rank() over(partition by ...order by ...)
select * from(select t.*,rank() over(partition by t.type order by t.scope ) a from TEST t) a where a.a<3
--dense_rank()分级 连续排序
select t.*,dense_rank() over(partition by t.type order by t.scope)a from test t
--rank()分级 跳跃排序
select t.*,rank() over(partition by t.type order by t.scope)a from test t
select * from Test t where 2>(select count(*) from Test a where t.type=a.type and t.scope>a.scope)
select t.* from Test t,(select a.type,max(a.scope) scope from TEST a group by a.type) d where t.type=d.type and t.scope=d.scope
--笛卡尔乘积
select * from Test t,Test a
select t.* from Test t,(select a.type,max(a.scope) maxscope,min(a.scope) minscope from TEST a group by a.type) d where t.type=d.type and t.scope=d.scope
--
select t.*,d.maxscope-t.scope maxscope,t.scope-d.minscope minscope
from Test t,
(select a.type, max(a.scope) maxscope, min(a.scope) minscope
from TEST a
group by a.type) d
where t.type = d.type
--min()/max() over(partition by ...)
select t.*,
nvl(max(t.scope) over(partition by t.type), 0) - t.scope maxscope,
t.scope - nvl(min(t.scope) over(partition by t.type), 0) minscope
from test t
--lead()/lag() over(partition by ... order by ...)
select t.*,lead(t.scope,1,0)over(partition by t.type order by t.scope) a--同组后一个
from test t
select t.*,lag(t.scope,1,0)over(partition by t.type order by t.scope) a--同组前一个
from test t
select t.*,
first_value(t.scope) over(partition by t.type) first_sal,
last_value(t.scope) over(partition by t.type) last_sal,
sum(t.scope) over(partition by t.type) sum_sal,
avg(t.scope) over(partition by t.type) avg_sal,
count(t.scope) over(partition by t.type) count_num,
row_number() over(partition by t.type order by t.scope) row_num
from test t
--注:带order by子句的方法说明在使用该方法的时候必须要带order by
- 解析Oracle中sql语句的复杂查询
- oracle sql语句复杂查询
- Oracle 查询并删除重复记录的SQL语句
- oracle 数据库的管理工具 PL/SQL_Developer 的简易使用 与Java 连接并查询显示出数据
- oracle查询不重复多列sql写法
- Oracle 查询并删除重复记录的SQL语句
- 常用查询Oracle的表,视图,存储过程,用户等SQL命令
- 查询oracle比较慢的session和sql
- ibatis动态多条件查询及模糊查询(oracle,mysql,sql)
- ORACLE SQL: 从一个表中查询数据插入另一个表中
- Oracle SQL查询语句转mysql
- [推荐]ORACLE SQL:经典查询练手第三篇(不懂装懂,永世饭桶!)
- Oracle、SQL server、MySQL数据库中分页查询的SQL语句
- oracle查询sql练习技巧(这个很实用,不是吹的)
- oracle的表的数据管理3 -- 复杂查询
- 不同数据库中查询前几条记录的用法(SQL Server/MYSQL /Oracle/Postgresql)
- Oracle实现Top查询(sql分页)
- oracle常用经典SQL查询
- SQL 简单,复杂查询,基本函数查询
- Oracle 性能调优之:使用 V$SQL_PLAN 视图查询内存中的执行计划