的總和我有一個表TEST需要計算加班
AccountName AccountIndex AccountID StartTime EndTime checkouttime
ABC 3 7 07:00:00.00 16:00:00.00 2016-07-22 17:03:00
ABC 3 7 07:00:00.00 16:00:00.00 2016-07-23 16:00:00
ABC 3 7 07:00:00.00 16:00:00.00 2016-07-25 17:04:00
我要計算加班的總和。
我想這
select name,accountid,case when (cast(CheckOutTime as time) < EndTime) then '-' else '' end +
convert(varchar(8),
dateadd(minute,
abs(
DATEDIFF(minute,
cast(CheckOutTime as time)
, EndTime)
)
,0)
,108) as Overtime
from test
,我得到的O/P爲
name accountid Overtime
ABC 7 01:03:00
ABC 7 00:00:00
ABC 7 01:04:00
我想有一個像加班
name accountid Overtime
ABC 7 02:07:00
總和O/P如何做到這一點
告訴它由兩個人來總結的價值和組,像往常一樣 –
@SamiKuhmonen我已經嘗試過案件時(cast(sum(CheckOutTime as time))
將總和作爲最外層函數,因爲您正在對結果進行求和 –