的总和我有一个表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))
将总和作为最外层函数,因为您正在对结果进行求和 –