I'm a complete SQL novice. I want to display a simple grid.....
- Sign up......>30.....30-60.....60-90.....>90.....Total
- Feb...............4..........30........... 6 ......... 0 .......40
- Mar ............. 0 .........11 ...........1 ..........4 .......16
- Apr
- May etc
- Jun etc
Where total represents the total of number of customer sign ups per month, and where the likes of '30-60' represents the number sign ups on the date 30-60 days since today's date
The query I am using is as follows......
SELECT case MONTH(Datecreated)
when 2 then 'Febrary'
when 3 then 'March'
when 4 then 'April'
when 5 then 'May'
when 6 then 'June'
end as 'Signup Month',
(select count(*) from WS_USER_DETAILS where datediff(day, datecreated, GETUTCDATE()) < 30 ) as '<= 30 days',
(select count(*) from WS_USER_DETAILS where datediff(day, datecreated, GETUTCDATE()) between 30 and 60) as '<= 60 days',
(select count(*) from WS_USER_DETAILS where datediff(day, datecreated, GETUTCDATE()) between 60 and 90) as '<= 90 days',
(select count(*) from WS_USER_DETAILS where datediff(day, datecreated, GETUTCDATE()) >90) as '<= 120 days',
count(userid) AS 'Total' FROM WS_USER_DETAILS
group by MONTH(Datecreated)
The problem I have is.... I want to run the select statements for each month. However it populates all months. For example......
- Sign up......>30.....30-60.....60-90.....>90.....Total
- Feb...............0..........11........... 1 ......... 4 .......40
- Mar ............. 0 .........11 ...........1 ..........4 .......16
If possible can someone advise me on how to run the select statements for each month? Thanks