i am trying to group days between two date filters by month. Is it possible to do this in mysql.
Example : StartDate : 2012-01-19 EndDate: 2012-03-24
The query should return days grouped by month
Jan : 19
Feb : 29
Mar :24
Apr : 0
May : 0 etc
Is there a way to do this?
Thanks!
this query will work for you for a limited date range(past 1,00,000 days). but better way would be to write a separate function or procedure with
WHILEloop.New answer for your question in comment: just had a question, how can I do a JOIN to another table using this query. The basic idea is I have a Bookings table which has a startDate and an endDate, and using these as parameters for the _date BETWEEN , I need to find out the number of days for each month. Any suggestions on how I could do that? Also is it possible to return the results in a single row rather than multiple rows:
see SQL FIDDLE DEMO HERE: