DrJohnZoidberg
Honorary Master
I am trying to write an efficient query in MySQL to compare financial figures between two periods of different years.
For instance I want to compare our sales figures during the following periods:
October 1, 2013 to October 22, 2013
October 1, 2012 to October 22, 2012
October 1, 2011 to October 22, 2011
etc
etc
Unfortunately my SQL skills are much to be desired and looks like my first attempt has made an impossible query:
It should check what the latest date is in the financial_main table then use that as the cut off date for the other years too.
Help
For instance I want to compare our sales figures during the following periods:
October 1, 2013 to October 22, 2013
October 1, 2012 to October 22, 2012
October 1, 2011 to October 22, 2011
etc
etc
Unfortunately my SQL skills are much to be desired and looks like my first attempt has made an impossible query:
Code:
SELECT brand, date, transfers_in
FROM financial_main
WHERE (MONTH(date) BETWEEN MONTH((now() - INTERVAL 1 MONTH)) AND MONTH(now()))
AND (DAY(date) BETWEEN 1 AND DAY((SELECT MAX(date) from financial_main LIMIT 1)))
It should check what the latest date is in the financial_main table then use that as the cut off date for the other years too.
Help
Last edited: