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...
Continue Reading This Article
Enjoy this article as well as all of our content, including E-Guides, news, tips and more.
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.