0

エイリアスを直接計算できないことは理解していますが、エイリアス (totaltime) の合計を求める方法はありますか? 事前に助けてくれてありがとう。

    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
4

1 に答える 1

0

抽象化の別のレイヤーを追加するだけです;)

SELECT TIME_FORMAT(sec_to_time(sum(timecard.totaltime)),'%H:%i' ) FROM 
(
SELECT *,
    TIMEDIFF( out_time, in_time ) , 
    TIMEDIFF( lunch_in, lunch_out ) , 
    ADDTIME( TIMEDIFF( out_time, in_time ) , TIMEDIFF( lunch_in, lunch_out ) ) , 
    ADDTIME( TIMEDIFF( out_time, in_time ) , 
    TIMEDIFF( lunch_in, lunch_out ) )
AS totaltime        
FROM
    timecard
WHERE
    comp_id='129'
AND
    MONTH(`date`) = MONTH(NOW())
GROUP BY emp_id
) timecard

フィドルへのリンク: http://sqlfiddle.com/#!2/b33d8/16/0

于 2013-08-14T21:31:53.480 に答える