I have a table that lists playerID
along with a startDate
and endDate
column. These are timestamps.
e.g.
playerID startDate endDate
1 2017-06-01 12:00:00 2017-06-01 12:05:00
1 2017-06-01 13:30:00 2017-06-01 13:33:00
1 2017-08-04 14:57:00 0000-00-00 00:00:00
I am trying to run a query to get the total number of seconds between the startDate
and endDate
for a specific player. If the endDate
is 0000-00-00 00:00:00
then I should use the current time.
Here is what I have tried:
select
IF(endDate = '0000-00-00 00:00:00', CURRENT_TIMESTAMP, endDate) as finishDate,
sum((startDate-finishDate)) as timeTaken
from table where playerID=1 group by playerID
This has two issues. I don't think I can use finishDate
as I get an unknown column error. I also want the sum of all rows for playerID 1