2
아래 코드에서 UserID 값이 무엇인지에 따라 AdminDuration 및 BreakDuration을 합산합니다. 지금은 알아낼 수 없으며 모든 기간의 값을 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