问题
AS-IS:
ID Version
5587138 1
6460704 2
6537612 3
6264608 4
TO-BE:
ID Version
5587138 1
6264608 2
6460704 3
6537612 4
I have to re-order the IDs to match the version order. The data is coming from the same table. I am currently trying to use PL/SQL. I really need help on this issue. Thank you.
回答1:
You can use the merge
statement as follows:
merge into your_table trg
using (select id, row_number() over (order by id) as version from your_table) src
on (trg.id = src.id)
when matched then
update set trg.version = src.version;
回答2:
My advice would be don't change the version numbers since if the same version is there for more than one id but use the version no required based on rownum
SELECT ID,Coldata,rownum version
FROM ( SELECT ID,Coldata, version FROM TABLE ORDER BY ID,Coldata);
来源:https://stackoverflow.com/questions/60993358/how-do-i-re-order-data-in-the-same-table