Drawing on from this other post of StackOverflow.com which I found useful.
I was wondering if it is possible to group by using date ranges that I don't explicitly define.
So to clarify, say I have a table called Person and a column called Date Of Birth.
I would like to group by and count the number of people born in a period.
So it would look something like this.
Born Count
Mar1980 25
Apr1980 452
May1980 42
...
Dec1993 452
The period could be weeks, months and quarters.
If I used the other solution, I would need to specify every single date range, even with months and years, it would take a long time as people's date of birth vary a lot.
select t.DOB as [dob], count(*) as [number of occurences]
from (
select user_id,
case when date >= '1980-01-01' and date < '1980-02-01 then 'Jan 1980'
when date >= '1980-02-01' and date < '1980-03-01 then 'Feb 1980'
...
when date >= '1990-03-01' and date < '1990-04-01 then 'Mar 1990'
else 'Null' end as DOB
from Person) t
group by t.DOB
Is there any solution you can think of that can allow me to specify just the size of the interval I want the data ranges to be and group by these date ranges?