IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Updating Column in a table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ssowmya

New User


Joined: 10 Oct 2006
Posts: 40

PostPosted: Wed Dec 27, 2006 12:24 pm
Reply with quote

Hi

I need to do the foll...I have a table TABLE1 with foll columns
Code:
Name    Seq
---------------
N1         1
N2         1
N2         1
N3         1
N3         1
N3         1
N3         1

Where Seq is populated with '1' initially. I should update the table so that the seq number is incremented for the same name...That is...the resultant table should be
Code:
Name    Seq
---------------
N1         1
N2         1
N2         2
N3         1
N3         2
N3         3
N3         4

Could anyone pls help....
Back to top
View user's profile Send private message
raghunathns

Active User


Joined: 08 Dec 2005
Posts: 127
Location: rochester

PostPosted: Thu Dec 28, 2006 12:22 am
Reply with quote

try like this.
Code:
UPDATE TABLE1 A
SET   COL2 = ( SELECT COUNT(*)
                       FROM TABLE1 B
                       WHERE A.COL1 = B.COL1
                       AND B.COL2 = 1)

------------
Code:
select * from table1 order by col1, col2.


you will get the result.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top