Select for a specific period in MySQL

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 want to go back two months ago I replace DAY with MONTH :

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

But how do I go back 2 months and 5 days?

    
asked by anonymous 26.09.2018 / 20:01

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 .

    
26.09.2018 / 20:05