Select for a specific period in Mysql

Asked

Viewed 118 times

1

I know that if I want to query the date 5 days ago, I use the following Query:

SELECT * FROM Tabela WHERE Data = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 5 DAY);

Or you want to go back two months ago I replace the DAY for MONTH:

SELECT * FROM Tabela WHERE Data = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 2 MONTH);

However, how do I go back 2 months and 5 days?

1 answer

2


One possibility is to do 2 operations:

WHERE Data = DATE_SUB(DATE_SUB(CURRENT_DATE, INTERVAL 2 MONTH), INTERVAL 5 DAY)

Other:

WHERE Data = CURRENT_DATE + INTERVAL - 2 MONTH + INTERVAL - 5 DAY;


See both working on SQL Fiddle.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.