zoukankan      html  css  js  c++  java
  • 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

    显示结果如下:

  • 相关阅读:
    线性表——(2)单向链表
    线性表——(1)顺序表
    UVa 1592 数据库
    UVa 12096 集合栈计算机
    Python 协程
    Python 多线程及进程
    Python 日志(Log)
    Python 函数式编程
    Python基础
    DB2 获取前两天的数据
  • 原文地址:https://www.cnblogs.com/liuyudong0825/p/7073588.html
Copyright © 2011-2022 走看看