I am writing a query in which I have to get the data for only the last half year: All data from the current date and a half year ago. Found this for 1 year in SQL but it's not working in Oracle:
SELECT ... From ... WHERE date > DATEADD(year,-1,GETDATE())
dateadd
的等效功能是add_months
SELECT ... From ... WHERE date > add_months(sysdate, -6)
Use ADD_MONTHS in your filter predicate.
For example,
SQL> SELECT ADD_MONTHS(SYSDATE, -6) FROM DUAL
ADD_MONTH
---------
29-OCT-14
SQL>
Modify your query as:
WHERE date > ADD_MONTHS(SYSDATE, -6)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.