标签:超出 uid pre 效率 targe efault varchar2 width 等级
RANK()
dense_rank()
【语法】RANK ( ) OVER ( [query_partition_clause] order_by_clause )
dense_RANK ( ) OVER ( [query_partition_clause] order_by_clause )
【功能】聚合函数RANK 和 dense_rank 主要的功能是计算一组数值中的排序值。
【参数】dense_rank与rank()用法相当,
【区别】dence_rank在并列关系是,相关等级不会跳过。rank则跳过
rank()是跳跃排序,有两个第二名时接下来就是第四名(同样是在各个分组内)
dense_rank()l是连续排序,有两个第二名时仍然跟着第三名。
【说明】Oracle分析函数
ROW_NUMBER()
【语法】ROW_NUMBER() OVER (PARTITION BY COL1 ORDER BY COL2)
【功能】表示根据COL1分组,在分组内部根据 COL2排序,而这个值就表示每组内部排序后的顺序编号(组内连续的唯一的)
row_number() 返回的主要是“行”的信息,并没有排名
【参数】
【说明】Oracle分析函数
主要功能:用于取前几名,或者最后几名等
sum(...) over ...
【功能】连续求和分析函数
【参数】具体参示例
【说明】Oracle分析函数
lag()和lead() 【语法】 lag(EXPR,<OFFSET>,<DEFAULT>) OVER ( [query_partition_clause] order_by_clause ) LEAD(EXPR,<OFFSET>,<DEFAULT>) OVER ( [query_partition_clause] order_by_clause ) 【功能】表示根据COL1分组,在分组内部根据 COL2排序,而这个值就表示每组内部排序后的顺序编号(组内连续的唯一的) lead () 下一个值 lag() 上一个值 【参数】 EXPR是从其他行返回的表达式 OFFSET是缺省为1 的正数,表示相对行数。希望检索的当前行分区的偏移量 DEFAULT是在OFFSET表示的数目超出了分组的范围时返回的值。 【说明】Oracle分析函数
CREATE TABLE TEST_Y( ID VARCHAR2 (32) PRIMARY KEY , NAME VARCHAR2 (20), AGE NUMBER(3 ), DETAILS VARCHAR2 (1000) );
INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘海子‘,20 ,‘面朝大海,春暖花开‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘海子‘,30 ,‘面朝大海,春暖花开‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘贝多芬‘,43 ,‘致爱丽丝‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘普希金‘,34 ,‘假如生活欺骗了你‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘杨过‘,23 ,‘黯然销魂掌‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘小龙女‘,32 ,‘神雕侠侣‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘李清照‘,21 ,‘寻寻觅觅、冷冷清清‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘周芷若‘,18 ,‘峨眉‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘赵敏‘,18 ,‘自由‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘张无忌‘,20 ,‘倚天屠龙记‘); INSERT INTO TEST_Y VALUES(SYS_GUID(), ‘张无忌‘,30 ,‘倚天屠龙记‘); SELECT * FROM TEST_Y;
SELECT NAME ,AGE,DETAILS,ROW_NUMBER() OVER(PARTITION BY NAME ORDER BY AGE DESC) FROM TEST_Y;
SELECT * FROM (SELECT NAME,AGE,DETAILS ,ROW_NUMBER() OVER( PARTITION BY NAME ORDER BY AGE DESC)RN FROM TEST_Y )WHERE RN= 1;
SELECT NAME ,AGE,DETAILS , RANK() OVER (PARTITION BY NAME ORDER BY AGE DESC) FROM TEST_Y;
(1) SELECT NAME ,AGE,DETAILS, LAG(NAME ,1, ‘sue‘) OVER (PARTITION BY NAME ORDER BY AGE DESC ) FROM TEST_Y;
(2) SELECT NAME ,AGE,DETAILS, LAG(NAME ,2, ‘sue‘) OVER (PARTITION BY NAME ORDER BY AGE DESC ) FROM TEST_Y;
(3) SELECT NAME ,AGE,DETAILS, LAG(NAME ,2, ‘sue‘) OVER (ORDER BY AGE DESC ) FROM TEST_Y;
(1)SELECT NAME ,AGE,DETAILS, LEAD(NAME ,1, ‘sue‘) OVER (PARTITION BY NAME ORDER BY AGE DESC ) FROM TEST_Y;
(2) SELECT NAME ,AGE,DETAILS, LEAD(NAME ,2, ‘sue‘) OVER (PARTITION BY NAME ORDER BY AGE DESC ) FROM TEST_Y;
(3) SELECT NAME ,AGE,DETAILS, LEAD(NAME ,1, ‘sue‘) OVER (ORDER BY AGE DESC ) FROM TEST_Y;
(1) SELECT NAME ,AGE,DETAILS,ROW_NUMBER() OVER(PARTITION BY NAME ORDER BY AGE DESC),SUM (AGE) OVER( PARTITION BY NAME ORDER BY AGE DESC) FROM TEST_Y;
(2) SELECT NAME ,AGE,DETAILS,ROW_NUMBER() OVER(PARTITION BY NAME ORDER BY AGE DESC),SUM (AGE) OVER( PARTITION BY NAME) FROM TEST_Y;
(3)SELECT NAME ,AGE,DETAILS,ROW_NUMBER() OVER(PARTITION BY NAME ORDER BY AGE DESC),SUM (AGE) OVER( ORDER BY AGE DESC NULLS LAST ) FROM TEST_Y;
(4) SELECT NAME ,AGE,DETAILS, SUM(AGE) OVER () FROM TEST_Y;
转转转---ROWNUMBER() OVER( PARTITION BY COL1 ORDER BY COL2)用法
标签:超出 uid pre 效率 targe efault varchar2 width 等级
原文地址:http://www.cnblogs.com/tenWood/p/7609273.html