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
 

 

I need a query for this situation

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: I need a query for this situation
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Wed May 18, 2005 8:17 pm    Post subject: Re: i need query for this situalation?
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    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
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
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
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm


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