![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm having a problem reordering my id_order column sample table ID ID_ORDER 1 1 1 3 1 4 2 1 2 2 3 1 3 2 3 3 3 5 I would like to know the best approach to update the id_order column. ID ID_ORDER 1 1 1 2 1 3 2 1 2 2 3 1 3 2 3 3 3 4 Thanks in advance |
#3
| |||
| |||
|
|
On 2012-01-03 17:15, Business Minded Men wrote: I'm having a problem reordering my id_order column sample table ID * * * * * *ID_ORDER 1 *1 1 *3 1 *4 2 *1 2 *2 3 *1 3 *2 3 *3 3 *5 I would like to know the best approach to update the id_order column. ID * * * * * *ID_ORDER 1 *1 1 *2 1 *3 2 *1 2 *2 3 *1 3 *2 3 *3 3 *4 Thanks in advance * *WITH corrected_table AS ( * * *SELECT ID_ORDER, ROW_NUMBER() OVER (PARTITION BY ID ORDER BY ID_ORDER) AS NEW_ID_ORDER * * *FROM sample_table * *) * *UPDATE corrected_table SET ID_ORDER = NEW_ID_ORDER; -- J.- Hide quoted text - - Show quoted text - |
#4
| |||
| |||
|
|
Lets say I wanted to start ID_ORDER at a specific number and increment from there so all ID_ORDERS are unique. Can I declare a variable and increment after each update? |
![]() |
| Thread Tools | |
| Display Modes | |
| |