一、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

最新文章

  1. js对文本框特殊字符串过滤
  2. MySQL 各种超时参数的含义
  3. Ubuntu 64位下搭建ADT的种种问题
  4. C++折半插入排序
  5. Zabbix页面遇到历史记录的乱码需要修改数据库
  6. (C#)使用队列(Queue)解决简单的并发问题
  7. Cocos2d-x——Cocos2d-x 屏幕适配新解【转载】
  8. spring mvc综合easyui点击上面菜单栏中的菜单项问题
  9. [HAOI2010]软件安装
  10. 如何查询oracle数据库中的各种角色
  11. python中json序列化的东东
  12. 公钥密钥理解,signed cookie
  13. [转]使用keepalived搭建主备切换环境
  14. Linux中一个网卡含有多个IP,将从IP升级为主IP的方法
  15. lua元表详解
  16. javascript弹层
  17. jenkins之配置git认证方式
  18. php中的XML DOM(11)
  19. CentOS6安装各种大数据软件 第五章:Kafka集群的配置
  20. HDU 5707 Combine String(动态规划)

热门文章

  1. reshape中的-1
  2. 禅道CMS 获文件名脚本
  3. 音频增益响度分析 ReplayGain 附完整C代码示例【转】
  4. linux shell语言编程规范安全篇之通用原则【转】
  5. vs2012 连接oracle11g 及数据的insert及select 的总结
  6. linux系统时钟和硬件时钟不一致
  7. MySQL 修改数据
  8. C++ : Boost : Rational 有理数类
  9. MySQL学习笔记:delete from与truncate table的区别
  10. ASP.NET Identity 修改表名和主键类型