Re: Using RANK in an update
- From: "Michel Cadot" <micadot{at}altern{dot}org>
- Date: Fri, 22 Dec 2006 07:58:40 +0100
"Maxim Demenko" <mdemenko@xxxxxxxxx> a écrit dans le message de news: emf482$4eu$00$1@xxxxxxxxxxxxxxxxxxxx
| Mike C schrieb:
| > I was trying to fill in blanks in a number field:
| >
| >
| > I am curious though, if there is a way to make the update directly
| > using RANK?
|
|
| scott@ORA102> select * from test;
|
| A B
| ---------- ----------
| 1 1
| 2 2
| 3 4
| 4 6
|
| scott@ORA102> update test
| 2 set b=
| 3 (with t as ( select a,b,rank() over(order by a) rank_a from test
| test)
| 4 select rank_a from t where t.a=test.a and t.b=test.b);
|
| 4 rows updated.
|
| scott@ORA102>
| scott@ORA102> select * from test;
|
| A B
| ---------- ----------
| 1 1
| 2 2
| 3 3
| 4 4
|
| For this approach however, combination of a and b should be unique (it
| may be not unique, if you go the CTAS way).
|
| Best regards
|
| Maxim
Use rowid to identify your rows:
update test
set b =
(with t as (select rowid rid,rank() over(order by a) rank_a from test)
select rank_a from t where t.rid = test.rowid);
Regards
Michel Cadot
.
- Follow-Ups:
- Re: Using RANK in an update
- From: Maxim Demenko
- Re: Using RANK in an update
- References:
- Using RANK in an update
- From: Mike C
- Re: Using RANK in an update
- From: Maxim Demenko
- Using RANK in an update
- Prev by Date: Re: Using RANK in an update
- Next by Date: Re: Using RANK in an update
- Previous by thread: Re: Using RANK in an update
- Next by thread: Re: Using RANK in an update
- Index(es):