If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Does DB2 UDB 7.2 have RRN fuction?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-05, 00:20
act7656 act7656 is offline
Registered User
 
Join Date: Mar 2004
Posts: 24
Does DB2 UDB 7.2 have RRN fuction?

Hi there,

Juz wonder whether in DB2 UDB 7.2 for windows does have the RRN function?

actually my objective is :

find the last 5 pervious row in the record.

eg: in the calendar table (without saturday,sunday n public holiday --> since this calendar table is used for stock exchange)

let say today is 24 Feb 2005, the last 5 trading day is 18 Feb 2004.

if not using RRN what othe function i can use in DB2 to achieve this?
__________________
Hello
Reply With Quote
  #2 (permalink)  
Old 02-25-05, 00:41
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Why don't you post the DDL for your calendar table and give some examples of how the table is populated with data.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 02-25-05, 01:35
act7656 act7656 is offline
Registered User
 
Join Date: Mar 2004
Posts: 24
Post Sample data

D_Trade L5_D_Trade
2004-02-01 2004-01-26
2004-02-02 2004-01-27
2004-02-03 2004-01-28
2004-02-04 2004-01-31
2004-02-07 2004-02-01
2004-02-08 2004-02-02
... ...
... ...
... ...

This is how the final tables looks like which need to get from CALENDAR TABLE.

Below is the sample data for calendar :

SELECT *
FROM SIMS.CALENDAR
WHERE YEAR(D_TRADE) = 2004
AND MONTH(D_TRADE) in (1,2)
ORDER BY D_TRADE


D_TRADE
2004-01-02
2004-01-05
2004-01-06
2004-01-07
2004-01-08
2004-01-09
2004-01-12
2004-01-13
2004-01-14
2004-01-15
2004-01-16
2004-01-19
2004-01-20
2004-01-21
2004-01-22
2004-01-23
2004-01-26
2004-01-27
2004-01-28
2004-01-29
2004-01-30
2004-02-02
2004-02-03
2004-02-04
2004-02-05
2004-02-06
2004-02-09
2004-02-10
2004-02-11
2004-02-12
2004-02-13
2004-02-16
2004-02-17
2004-02-18
2004-02-19
2004-02-20
2004-02-23
2004-02-24
2004-02-25
2004-02-26
2004-02-27

please refer the attachement for the full detail. thanks
Attached Files
File Type: doc calendar.doc (55.0 KB, 48 views)
__________________
Hello
Reply With Quote
  #4 (permalink)  
Old 02-25-05, 02:01
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
One option could be to use the row_number function ... Check the SQL Reference for details
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #5 (permalink)  
Old 02-25-05, 02:10
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
select d_trade
from
(select d_trade, rownumber() over
(order by d_trade desc)
as RN from db2inst1.calendar where d_trade <= '2004-02-24' fetch first 5 rows only)
as TR where RN = 5
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On