akoper@web4000.com wrote:
[color=blue]
> I was on Christmas vacation and am just getting back to this. I am not
> sure why you need a create table or insert statement - I think the
> example table shows you everything you need to know. Table:
>
> task_ID task date_time
> 1 plan meal 2004-12-01 9:53:00
> 2 go to grocery store 2004-12-01 15:53:55
> 3 cook food 2004-12-03 12:00:00
> 4 serve food 2004-12-03 18:00:00
>
> What SQL statement shows me how many seconds have passed between tasks
> 2 & 1, 3 & 2 and 4 & 3 for n number of tasks?[/color]
SELECT T.task_ID, T.task, T.date_time,
COALESCE(PrevT.task_ID),
UNIX_TIMESTAMP(T.date_time) - UNIX_TIMESTAMP(PrevT.date_time),
NULL) AS TaskDuration
FROM selfJoin AS T LEFT OUTER JOIN selfJoin AS PrevT
ON PrevT.task_ID = T.task_ID - 1
[color=blue]
> What SQL statement shows me how many seconds have passed between tasks
> 1 and the final task?[/color]
SELECT UNIX_TIMESTAMP(LaterT.date_time) -
UNIX_TIMESTAMP(EarlierT.date_time) AS TotalProjectTime
FROM selfJoin AS EarlierT INNER JOIN LaterT
WHERE EarlierT.task_ID = (SELECT MIN(task_ID) FROM selfJoin)
AND LaterT.task_ID = (SELECT MAX(task_ID) FROM selfJoin)
Regards,
Bill K.