I have the following query, it is working fine to show the cricket time played per day. All I need is to show 0 when no cricket is played. At the moment it is skipping those
You need a list of dates. The easiest way -- if you have data on each date, but just not for the where
conditions -- is to use conditional aggregation:
Select activity, cast(starttime as date) as date,
SUM(case when activity = 'cricket' and email = 'abc'
then datediff(second, starttime, endtime))/60.0
else 0
end) as TimePerDay
from users
where starttime >= dateadd(day, -15, last_update)
group by activity, cast(starttime as date);
Otherwise, if the dates are not in the table, then you need a list of dates. This can come from: