I´m struggling around with this problem.
I have a Table with 3 columns:
id, startDate, endDate
1, 2014-01-01, 2014-02-02
2, 2014-04-03, NULL
3, 2014-02-02, 2014-05-03
now i want to count all ids with special conditions: for example for month may:
SELECT COUNT(*) FROM Table WHERE startDate <= "2014-05-31" and (endDate >= "2014-05-01" or endDate is NULL)
How can i achieve this by grouping in year and month?
startDate should be always <= lastDayofGivenMonth and endDate >= firstDayofGivenMonth or Null
The result should look like this:
year, month, count
2014, 01, 1
2014, 02, 2
2014, 03, 2
2014, 04, 2
2014, 05, 2
2014, 06, 1
...
Thank you for any help!
Steve