I have already asked a similar question, but I still don't seem to be able to get my head around it. I have a column device_create_date on my sql database
2015-07-14 12:35:19
2015-07-15 12:45:37
2015-07-15 12:45:37
2015-07-16 12:35:37
2015-08-14 10:35:21
2015-08-14 12:15:36
I am aggregating these date values in weeks, but there are missing values in between the weeks, where I want these values to just equal 0 so that I can compere them with other metrics in an excel sheet. I created a dummy table "date" to join the values with, so that the select returns 0 for the weeks there are no values for.
Here is the query I used,
select date.year, week(device.device_create_date), count(*)
from device
join date
on date.week_of_year=week(device.device_create_date)
where device.id_customer = 1
group by device.year, date.WEEK_OF_YEAR
order by device.year, date.week_of_year;
Here is what I got back,
2010 26 7252
2010 31 3108
2010 45 7203
2010 1 9324
2010 2 7252
2010 3 2072
Here is what I want it to give me back;
2010 1 9324
2010 2 7252
2010 3 2072
2010 4 0
2010 5 0
2010 6 0
etc
btw these values don't seem to be matching the count on the database either, so I kinda know I'm doing something completely wrong but I am not great at this so any help and direction would be greatly appreciated.
Thank you in advance!!