Q

Query to retrieve data from past six months

I need a SQL query that gives me data over six months (i.e., between current month (June 6) and past month (Jan...

1).

SELECT * FROM MY_TABLE
WHERE DATE_COLUMN BETWEEN CURRENT_DATE-6*30 and CURENT_DATE;

If you get a problem with CURRENT_DATE try replacing CURRENT_DATE with TRUNC(SYSDATE) above.

Now, if your question is at any point in time you want to see data for the past six months, then you need to do your calculation of the To and From date based on the CURRENT_DATE (or SYSDATE) as 6*30 is not the exact six month from current date.

Next Steps

Query data directly from APIs

 

Dig Deeper on Using Oracle PL-SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close