我正在编写一些 SQL 代码来查询 Lync LCSCDR 数据库。
如果有人从外部呼叫响应组而另一个响应组,则记录将进入sessionDetails
表(和Voipdetails
表) - 以反映所做的呼叫。
但是,似乎无法确定谁接听了电话。该user2id
列填充了响应组的userid
(来自Users
表格)而不是接听电话的人。有谁知道是否有办法猜测谁接听了电话?
查询是:
SELECT
sd.SessionIdTime,
sd.SessionEndTime,
DATEDIFF(
ss,
sd.SessionIdTime,
ISNULL(sd.SessionEndTime, sd.SessionIdTime)
) AS duration,
ph1.PhoneUri AS caller1,
ph2.PhoneUri AS receiver1,
U1.UserUri AS user1uri,
U2.UserUri AS user2uri,
U3.UserUri AS refeereruri,
sd.User1Id,
sd.User2Id,
sd.ReferredById,
sd.IsUser1Internal,
sd.IsUser2Internal,
sd.SessionIdTime,
voipd.*,
'|||',
sd.*
FROM
dbo.VoipDetails AS voipd
INNER Join
dbo.SessionDetails AS sd
ON
(
voipd.SessionIdTime = sd.SessionIdTime AND
voipd.SessionIdSeq = sd.SessionIdSeq
)
LEFT OUTER JOIN
dbo.Users AS U2 -- still 4795 with outer
ON
U2.UserId = sd.User2Id
LEFT OUTER JOIN
dbo.Users AS U1
ON
U1.UserId = sd.User1Id
LEFT OUTER JOIN
dbo.Users AS U3
ON
U3.UserId = sd.ReferredById
LEFT OUTER JOIN
dbo.Phones AS ph1
ON
ph1.PhoneId = voipd.FromNumberId
LEFT OUTER JOIN
dbo.Phones AS ph2
ON
ph2.PhoneId = voipd.ConnectedNumberId
WHERE
sd.SessionIdTime > (GETDATE() - 2)
AND sd.MediaTypes = 16
AND voipd.FromGatewayId is not null -- external
AND User1Id IS NULL