Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Updating Column in a table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Updating Column in a table
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    Post subject: Updating Column in a table
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Updating the counters after eliminati... PANDU1 DFSORT/ICETOOL 12 Mon Nov 21, 2016 9:47 am
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us