Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> SQL update question

SQL update question

From: Kamal <kamal80_at_virgilio.it>
Date: 22 Nov 2004 07:18:45 -0800
Message-ID: <4e766a02.0411220718.252498ed@posting.google.com>


Hi everybody.

If I have a table like this:

col0(number) cnt (number)

0              (null)
0              (null)
0              (null)
1              (null)
1              (null)
2              (null)

And I want:

col0(number) cnt (number)

0              3
0              3
0              3
1              2
1              2
2              1

where cnt is the count of the records with different values in col0: what would be the fastest single update to achieve this?

I would do

update t t1 set t1.cnt = (select count(*) from t t2

                          where t1.col0 = t2.col0
                          group by t2.col0);

Is there a better way?
I know there's a redundancy but I want it.

Thank you.

Kamal Received on Mon Nov 22 2004 - 09:18:45 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US