在下面的代码中,我希望AdminDurationandBreakDuration根据 value 的值求和UserID。目前我无法弄清楚,它将所有Durations 的值与ReasonCode7 相加。结果每个UserId都有相同的Duration(不是我想要的!)。
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