Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Query to fetch data from the last 30 days?

Hi I am new to Oracle. How do I do a simple statement, for example get product id from the last 30, or 20 days purchase date?

SELECT productid FROM product WHERE purchase_date ?  
like image 486
miracle Avatar asked Mar 06 '11 13:03

miracle


People also ask

How can I get last 7 days data in SQL?

Here's the SQL query to get records from last 7 days in MySQL. In the above query we select those records where order_date falls after a past interval of 7 days. We use system function now() to get the latest datetime value, and INTERVAL clause to calculate a date 7 days in the past.

How can I get 30 days before a date in SQL?

If you would like to subtract dates or times in SQL Server, use the DATEADD() function. It takes three arguments. The first argument is the date/time unit – in our example, we specify the day unit. Next is the date or time unit value.


1 Answers

SELECT productid FROM product WHERE purchase_date > sysdate-30 
like image 181
jgrabowski Avatar answered Nov 02 '22 20:11

jgrabowski