I'm showing up monthly user registered on my app. For that, I have used the below query, which is working fine. But with this query, if no user registered in the month of June then no data is there against June. I want a row with month June and all other information set to 0. Can anyone please help me out with this?
SELECT Month(createdon), count(*) as users,COUNT(if(roleid=1,1,NULL)) as instructor, COUNT(if(roleid=2,1,NULL)) as student FROM user_profile where Year(createdon) = Year(Now()) group by MONTH(createdon);
I am getting the output as:
Month(created on) | users | instructor | student |
3 | 4 | 3 | 1 |
4 | 7 | 5 | 2 |
Here, Month 3 and 4 corresponds to March and April respectively.
But the actual output is:
Month(created on) | users | instructor | student |
1 | 0 | 0 | 0 |
2 | 0 | 0 | 0 |
3 | 4 | 3 | 1 |
4 | 7 | 5 | 2 |
5 | 0 | 0 | 0 |
6 | 0 | 0 | 0 |