I'm trying to do a search from dates in MySql.
I need to get the total sum of a value where the year and month are smaller than the ones reported in the variable:
SELECT SUM(valor_pag) FROM controle WHERE MONTH(data_paga) < 07 and YEAR(data_paga) <= 2017
But he is ignoring months like: 08/2016, 09/2016, 10/2016, 11/2016, and 12/2016, because the month is conditioned to be less than 07 in MONTH(data_paga) < 07
.
My intention is to get all the records from the previous month back, understand? But the query understands that it should ignore months larger than 7, so that 08/2016, 09/2016, 10/2016, 11/2016 and 12/2016, or even 08/2015, 09/2015, 10/2015, 11 / 2015 and 12/2015 are left out, and so on
What could be wrong?