Oracle Partition By 的使用

Posted 一发寒冰箭

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle Partition By 的使用相关的知识,希望对你有一定的参考价值。

需求:以FSENDCCNAME分组找出FRECAMOUNT最大的一行信息;

解决方案 1:

SELECT T0.FSENDCCNAME,T0.FRECCCNAME
  FROM TMP0CE8366758A811E781D70050568 T0
       INNER JOIN
       (  SELECT FSENDCCNAME, MAX (FRECAMOUNT) FRECAMOUNT
            FROM TMP0CE8366758A811E781D70050568
           WHERE FGROUPING = 0
        GROUP BY FSENDCCNAME
        ORDER BY FSENDCCNAME, FRECAMOUNT DESC) T1
          ON     T1.FSENDCCNAME = T0.FSENDCCNAME
             AND T1.FRECAMOUNT = T0.FRECAMOUNT
 WHERE T0.FGROUPING = 0;

解决方案 2:

--按顺序排序
SELECT row_number () OVER (PARTITION BY fsendccname ORDER BY frecamount DESC)
                  rn,
               a.*
          FROM TMP0CE8366758A811E781D70050568 a
         WHERE fgrouping = 0 and FGROUPLEVEL<> 1

显示结果如下:

解决方案 3:

--跳跃排序

SELECT RANK () OVER (PARTITION BY FSENDCCNAME ORDER BY FRECAMOUNT DESC)
                  RN,
               A.*
          FROM TMP0CE8366758A811E781D70050568 A
         WHERE FGROUPING = 0 AND FGROUPLEVEL<> 1

显示结果如下:

解决方案 4:

--连续排序
SELECT DENSE_RANK () OVER (PARTITION BY FSENDCCNAME ORDER BY FRECAMOUNT DESC)
                  RN,
               A.*
          FROM TMP0CE8366758A811E781D70050568 A
         WHERE FGROUPING = 0 AND FGROUPLEVEL<> 1

显示结果如下:

以上是关于Oracle Partition By 的使用的主要内容,如果未能解决你的问题,请参考以下文章

Oracle Partition By 的使用

Oracle 能否使用 PARTITION BY 分析函数对查询使用谓词推送?

Oracle LISTAGG() 聚合查询用法 GROUP BY 和 PARTITION BY 的使用和比较

Oracle:Max、Partition by 还是 rownum?

oracle下的OVER(PARTITION BY)函数介绍

Oracle Partition By