MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Put a Seqnum for all rows selected

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
dhulipalla
Beginner


Joined: 24 Aug 2004
Posts: 21
Topics: 6

PostPosted: Mon May 21, 2007 10:25 am    Post subject: Put a Seqnum for all rows selected Reply with quote

Hi,

Is there a way I can get the desired result.
Code:

COLA   COLB
----   ----
AAA
AAA
AAA
BBB
BBB
BBB

EXPECTED RESULT:
---------------
COLA    COLB
----     ----
AAA      1
AAA      2
AAA      3
BBB      1
BBB      2
BBB      3

Thanks,
Krishna
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon May 21, 2007 10:46 am    Post subject: Reply with quote

dhulipalla,

Not possible with the existing features of DB2

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Tue May 22, 2007 1:38 am    Post subject: Reply with quote

kolusu,
dhulipalla,

if you have the special situation

- table with unique primary key
- selecting rows for a range of the primary key or all rows (see sample)

you you try this


Code:

   
   SELECT mykey , ROW# FROM xyz.mytab  TB1,
   TABLE (SELECT COUNT(*) AS ROW#
   FROM xyz.mytab   TB2
   WHERE TB2.mykey  < TB1.mykey) AS TEMP_TAB
   ORDER BY 2



But in general I agree, it's not possible.

regards,
bauer
Back to top
View user's profile Send private message
bdahelj
Beginner


Joined: 24 Apr 2007
Posts: 1
Topics: 0

PostPosted: Tue May 22, 2007 5:47 am    Post subject: Reply with quote

I guess that recursive sql can help you.
See http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/dsnapj14/APPENDIX1.5?DT=20061207131029

regards
Helena
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue May 22, 2007 6:04 am    Post subject: Reply with quote

bauer,

The query you have shown will only give you a seqnum for all the rows, but if you look at Op's request he needs to restart the seqnum for every key change. So your sql will not solve Op's problem even though he has a unique primary key.

dhulipalla,

1. Unload the table
2. Run the unload file thru sort. sort has the capability of numbering the duplicate rows.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Aug 06, 2007 10:37 am    Post subject: Online analytical processing (OLAP) specifications Reply with quote

As an update to this thread, the OLAP functions provided by Vsn8 & 9 of DB2 UDB provide interesting resetting & running totals aggregation functions.

The OLAP function RANK DENSE would work in this case if there was a second column in the row (that need not be selected) but was distinct within each first column group.

e.g.
Code:

COLUMN  FIRST         SECOND
VALUE     AAA           1
          AAA           2
          AAA           3
          BBB           4
          BBB           5
          CCC           6
          CCC           7

query
Code:

SELECT FIRST
     , DENSE_RANK() OVER
               (PARTITION BY FIRST ORDER BY SECOND ASC) AS RANK_EDLEVEL
FROM <TABLE>
ORDER BY FIRST, RANK_EDLEVEL;


results
Code:

AAAA         1
AAAA         2
AAAA         3
BBBB         1
BBBB         2
CCCC         1
CCCC         2

_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 06, 2007 10:46 am    Post subject: Reply with quote

dbzTHEdinosauer,

RANK function is NOT available on Z/OS DB2

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Aug 06, 2007 11:55 am    Post subject: Reply with quote

SC18-9854-00 DB2 Version 9.1 for z/OS SQL Reference
OLAP Specifications

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db29.doc.pdf/dsnsqk10.pdf?noframes=true

http://www-304.ibm.com/jct03001c/software/data/db2/zos/v9books.html
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 06, 2007 12:32 pm    Post subject: Reply with quote

dbzTHEdinosauer,

I stand corrected bonk Sorry about that.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Aug 06, 2007 2:24 pm    Post subject: Reply with quote

Once every 2 or 3000 answers; not a bad average.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group