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

I need a query for this situation


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

New User


Joined: 22 Mar 2005
Posts: 51
Location: chennai

PostPosted: Wed May 18, 2005 5:25 pm
Reply with quote

hi

I have one table is there . that table contain 2000 reacords are there. in that table contain date fields is there? but i want to retrive only last five days records only how to write the query?



naveens
Back to top
View user's profile Send private message
MGIndaco

Active User


Joined: 10 Mar 2005
Posts: 432
Location: Milan, Italy

PostPosted: Wed May 18, 2005 7:50 pm
Reply with quote

I've some problem in understanding your post but i think that you can subtract from current date all the day you need as you can see below:
Code:
SELECT * FROM MYDB.MYTB     
WHERE DATE = CURRENT_DATE - 5 DAYS
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Wed May 18, 2005 8:17 pm
Reply with quote

Is this code going to extract records only for last fifth day from today.

Quote:
I've some problem in understanding your post


I think naveensri2005 asked all the recs for the all last five days.

so it could have been.

Code:
SELECT * FROM MYDB.MYTB
            WHERE DATE IN (
                                      CURRENT_DATE,
                                      CURRENT_DATE - 1 DAYS.
                                      CURRENT_DATE - 2 DAYS.
                                      CURRENT_DATE - 3 DAYS.
                                      CURRENT_DATE - 4 DAYS.
                                    );


Regards,

Priyesh.
Back to top
View user's profile Send private message
MGIndaco

Active User


Joined: 10 Mar 2005
Posts: 432
Location: Milan, Italy

PostPosted: Wed May 18, 2005 8:28 pm
Reply with quote

Or you can also specify:

Code:
SELECT * FROM MYDB.MYTB     
WHERE DATE >= CURRENT_DATE - 5 DAYS

It's another way to do the same request...
Back to top
View user's profile Send private message
ajay_dheepak

New User


Joined: 12 May 2005
Posts: 32
Location: Chennai

PostPosted: Thu May 19, 2005 2:49 pm
Reply with quote

SELECT * FROM MYDB.MYTB
WHERE DATE >= CURRENT DATE - 4 DAYS
AND DATE <= CURRENT DATE;
Back to top
View user's profile Send private message
MGIndaco

Active User


Joined: 10 Mar 2005
Posts: 432
Location: Milan, Italy

PostPosted: Thu May 19, 2005 8:52 pm
Reply with quote

OPS... icon_redface.gif
Back to top
View user's profile Send private message
MGIndaco

Active User


Joined: 10 Mar 2005
Posts: 432
Location: Milan, Italy

PostPosted: Thu May 19, 2005 8:57 pm
Reply with quote

Code:
SELECT * FROM MYDB.MYTB
WHERE DATE BETWEEN CURRENT_DATE - 4 DAYS AND CURRENT_DATE

This is better... icon_wink.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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top