I'm not a db expert. I'm just working on a project where we need to show page views on daily basis between two dates selected by a user from a calendar. I have the following
SQL query that brings brings total number of page views like
SELECT DATE_FORMAT(created_at,'%d %b %Y') as this_date, count(*) as Views
from promotion_insights WHERE f_id = '2' AND p_id = '12'
AND created_at BETWEEN '2012-08-15' AND '2012-08-19'
GROUP BY this_date
Result comes like
----------------------
this_date View
---------------------
15 Aug 2012 3
16 Aug 2012 2
----------------------
I have also a calendar table and a store procedure.calendar table has one column of dates named (datefield). I have already generated dates by calling a stored procedure so don't worry about that. Now what I want, is to make a right join on date basis to above table having (this_date and view columns) with calendar table to show all_dates between selected by the user and put 0 for the dates having 0 views. count(*) is also making trouble by returing 1 instead 0
Expected output by the join I want is like this:
----------------------
this_date View
---------------------
15 Aug 2012 3
16 Aug 2012 2
17 Aug 2012 0
18 Aug 2012 0
19 Aug 2012 0
----------------------
Any help would be highly highly appreciated.