首页 > 代码库 > Oracle Partition By 的使用
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 的使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。