I have a table with id, play, starttime and endtime. I want to find the total play time per day. I think the query will be similar as the following but I am sure it is not right. It will be also very convenient if i get 0 when no game is played but if it is difficult I dont mind.
Select
id,
play,
date,
CASE
WHEN datediff(day, starttime, endtime) = 0 then sum(totaltime)
END as TimePerDay
from cte where starttime >= '2015-05-30 17:11:34.000'
group by id, playtime, starttime, endtime
I am looking for
id | play | Date | totaltime
1 | hockey | 05/06/2015 | 0
2 | hockey | 04/06/2015 | 0
3 | hockey | 03/06/2015 | 230
4 | hockey | 02/06/2015 | 10
5 | hockey | 01/06/2015 | 120
Can you try this
For Express Version :