the oracle row_number () usage

 

/*

The company needs to do when the system upgrade data migration, encountered a problem: the data structure of the new table the old table and heterogeneous, the old table is a serial number, the new table is the primary key (service number service number + serial number)

Finally found a window function row_number () + partition by would be the perfect realization of the next record, later encounter similar problems here directly copied, ha ha. (Partition by and group by both groups, but the feeling of the former than the latter effect is more flexible)

*/

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');

- the effect is good oh
/ *
000000000000000C 100 000 002 527 1
000000000000000C 100 000 002 526 2

1 100 002 456 768 222222222222222C
222222222222222C 2 100 002 456 767
222222222222222C 3 100 002 456 766
222222222222222C 4 100 002 456 765
222222222222222C 5 100 002 456 764
222222222222222C 6 100 002 456 762
222222222222222C 7 100 002 456 761
222222222222222C 8 100 002 390 482
* /

 

Guess you like

Origin www.cnblogs.com/heyt/p/11346239.html