oracle中row_number()的用法

2022-10-17,,

 

/*

公司做系统升级的时候需要数据迁移,遇到一个问题:新表的数据结构和旧表异构,旧表是流水号,新表是联合主键(业务号码+业务号码序号)

最后发现用窗口函数 row_number() + partition by 就可以完美的实现,这里记录下,以后再遇到类似问题就直接抄了,哈哈。(partition by和group by都是分组,但是感觉前者要比后者作用更灵活)

*/

select column1,
column2,
row_number() over(partition by column2 order by column2 desc) column2_seq
from t_cls_claim_beneficiary a
where column1 in ('222222222222222c', '000000000000000c');

--效果不错噢
/*
000000000000000c 100000002527 1
000000000000000c 100000002526 2

222222222222222c 100002456768 1
222222222222222c 100002456767 2
222222222222222c 100002456766 3
222222222222222c 100002456765 4
222222222222222c 100002456764 5
222222222222222c 100002456762 6
222222222222222c 100002456761 7
222222222222222c 100002390482 8
*/

 

《oracle中row_number()的用法.doc》

下载本文的Word格式文档,以方便收藏与打印。