Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | Id | lIST_1 |
- ----------------------
- | 1 | NULL |
- | 2 | JASON |
- | 3 | NULL |
- | 4 | BANDORAN |
- | 5 | NULL |
- | 6 | NULL |
- | 7 | SMITH |
- | 8 | NULL |
- | Id | lIST_1
- -----------------------
- | 1 | JASON |
- | 2 | BANDORAN |
- | 3 | SMITH |
- | 4 | NULL |
- | 5 | NULL |
- | 6 | NULL |
- | 7 | NULL |
- | 8 | NULL |
- select row_number() over (order by (select null)) as id, t.list_1
- from t
- order by (case when list_1 is not null then 1 else 2 end)
- with toupdate as (
- select row_number() over (order by (case when list_id is not null then 1 else 2 end), id
- ) as new_id,
- t.*
- from t
- )
- update toupdate
- set id = new_id
- where id <> new_id; -- no need to update if the value remains the same
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement