2
在下面的代码中,我希望AdminDuration和BreakDuration根据UserID的值进行求和。目前我无法弄清楚,并且它将所有持续时间的值与ReasonCode 7相加。结果,每个UserId的持续时间相同(不是我想要的!)。如果根据另一列中的值计算总和
Select SkillTargetID AS UserID,
(SELECT sum(Duration)
from [t_Agent_Event_Detail]
where ReasonCode = 7
and DateTime > convert(DATETIME, '2013-01-31 08:00', 21)) as AdminDuration,
(SELECT sum(Duration)
from [t_Agent_Event_Detail]
where ReasonCode = 6
and DateTime > convert(DATETIME, '2013-01-31 08:00', 21)
and SkillTargetID = [t_Agent_Event_Detail].SkillTargetID) as BreakDuration
from [t_Agent_Event_Detail]
GROUP BY SkillTargetID