SQL Challenge, getting historical data

time to read 1 min | 130 words

Here is an interesting problem that I had to face at work. I need to get historical data from this table. Basically, I need to count the number of opened bugs per months.

image

Id  OpenedAt   ClosedAt
--- ---------- -----------
1   2007-04-02  2007-09-01
2   2007-07-01  NULL
3   2007-07-01  2007-07-23

 

 

A solution to this with the data above should print (for 2007-04 to 2007-10):

Month Year Opened Bugs
4 2007 1
5 2007 1
6 2007 1
7 2007 2
8 2007 2
9 2007 1
10 2007 1

Have fun :-)