Request last 5 years

I want to request all products sold in the last 5 years.
This can be done as follows:

select * from products where time between sysdate-1826 and sysdate 

But is this also the best way instead of calculating all days and subtracting from sysdate ?

+8
sql database oracle time
source share
2 answers
 SELECT * FROM products WHERE date_column >= add_months( sysdate, -12*5 ) 

or

 SELECT * FROM products WHERE date_column >= sysdate - interval '5' year 

both will give you all the lines in the last 5 years (although you would usually like to add TRUNC to remove the temporary part if you really don't like whether the line was created on February 8, 2007 morning or afternoon).

+17
source share
 select * from products where time > DATE_SUB(NOW(), INTERVAL 5 YEAR) 

Saturday dates deducted after 5 years

0
source share

All Articles