当我运行它时(SQL Server 2008 R2):
SELECT [UserId]
,[StateDuration]
,[StatusKey]
FROM [AgentActivityLog]
WHERE [StatusDateTime] between '2012-01-01' and '2012-12-31'
我得到每个 UserId 的一行,如下所示: UserId StatusDateTime StatusKey
cfrinco 3456 Meeting
echartl 23456 Available
mbarbewar 3256 Lunch
bsantiago 46565 Available
bsantiago 79 Follow Up
fburger 5464 Available
它告诉我每个用户处于每个状态的时间(以秒为单位)。
UserId
当然,每个日期会有很多条目。
换句话说,用户在一天内将从可用到会议到可用到午餐再到可用等。
我想要做的是以秒为单位的总时间UserId
,StatusKey
每个日历日。所以它看起来像这样:
cfrinco 3456 Meeting '2012-01-01'
cfrinco 45678 Available '2012-01-01'
cfrinco 7845 Meeting '2012-01-02'
cfrinco 32541 Available '2012-01-02'
cfrinco 4455 Meeting '2012-01-03'
cfrinco 12456 Available '2012-01-03'
fburger 3456 Meeting '2012-01-01'
fburger 75489 Available '2012-01-01'
fburger 3541 Lunch '2012-01-01'
fburger 5486 Meeting '2012-01-02'
fburger 64587 Available '2012-01-02'
fburger 3614 Lunch '2012-01-02'
fburger 3225 Meeting '2012-01-03'
fburger 35414 Available '2012-01-03'
fburger 3745 Lunch '2012-01-03'
非常感谢您的帮助。