Wednesday, 14 August 2013

Find the sum of an alias then group by

Find the sum of an alias then group by

I understand that it is not possible to perform calculations on aliases
directly, but is there a way that I could find the sum of my
alias(totaltime)? Thanks for the help in advance.
SELECT *,
TIMEDIFF( time2, time1 ) ,
TIMEDIFF( time4, time3 ) ,
ADDTIME( TIMEDIFF( time2, time1 ) ,
TIMEDIFF( time4, time3 ) ) ,
TIME_FORMAT( ADDTIME( TIMEDIFF( time2, time1 ) ,
TIMEDIFF( time4, time3 ) ) , '%H:%i' )
AS totaltime
SUM(SELECT(totaltime)) AS sumtotal
FROM
timer
WHERE
groupid='100'
AND
MONTH(`date`) = MONTH(NOW())
GROUP BY userid

No comments:

Post a Comment