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

How to use Rank Function in DB2 Version 8


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
saratchandran

New User


Joined: 24 Dec 2006
Posts: 3
Location: India

PostPosted: Thu Jul 05, 2007 9:57 am
Reply with quote

Hi I have used this query in DB2 Ver 8
SELECT Col1,Col2,
RANK() OVER(ORDER BY Col2 DESC)
Cant We use Rank Function in DB2 Ver 8. Could any one tell me how to use Rank Function ?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jul 09, 2007 6:16 am
Reply with quote

Hello and welcome to the forums,

Why did you choose that particular syntax? What you have specified is an OLAP function, typically used in a data warehouse/cube environment.

If you are not working in an OLAP situation, my guess is that you will not use RANK or DENSERANK.

Following is a bit of info from IBM and you may want to search deeper on IBM web pages.

Quote:
the RANK function, which is an OLAP function provided by DB2 Universal Database? (DB2? UDB).

DB2 Cube Views supports the following OLAP functions that are provided by DB2 UDB:

RANK
Orders the rows and assigns a ranking to each row. The rank is defined as 1 plus the number of preceding rows that are distinct with respect to the ordering. If the relative order of two or more rows cannot be determined because they have duplicate row values, the same rank number is assigned. The ranking results might have gaps in the numbers if there are duplicate row values. Table 1 shows an example of what the ranking results are from the RANK function for a set of sample row values.

The typical syntax for the RANK function is:
RANK ( ) OVER (ORDER BY sort-key-expression expression-order)
where sort-key-expression is the set of data to be ranked, and expression-order is a keyword, ASC or DESC, that orders the values of the sort-key-expression in ascending or descending order. DB2 Cube Views requires that the sort-key-expression be an existing measure, not a column or attribute. Also, DB2 Cube Views does not support the PARTITION BY clause that is provided by DB2 UDB with this function. More information about the RANK function is available in the DB2 UDB Information Center.
Back to top
View user's profile Send private message
saratchandran

New User


Joined: 24 Dec 2006
Posts: 3
Location: India

PostPosted: Mon Jul 09, 2007 12:35 pm
Reply with quote

Thank you..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jul 09, 2007 7:40 pm
Reply with quote

You're welcome icon_smile.gif
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
Search our Forums:

Back to Top