我正在尝试从电话系统上的某些原始数据创建一些报告。该系统的呼叫来自多个位置,可能会也可能不会被应答,并且数据在呼叫请求,应答和挂断之间也可能有几行。最终,我希望为每个呼叫提供一个包含呼叫请求,开始,结束(以下简化)时间的行。还包括起点和终点,但未包含在简化查询中
我尝试创建行号和各种版本或以下版本,希望创建单行,但是联接中行号的变化是我要克服的问题。 [END] .RowNumber =(START.RowNumber-1)
WITH CallRowNum AS
(
SELECT (CASE WHEN Text LIKE 'Call request from%' THEN (LogTime)
ELSE NULL
END) AS REQUEST_TIME,
(CASE WHEN Text LIKE 'Start conversation%' THEN (LogTime)
ELSE NULL
END) AS CALL_START,
(CASE WHEN Text LIKE 'Call deleted%' THEN (LogTime)
ELSE NULL
END) AS CallEnd,
ROW_NUMBER() OVER (ORDER BY (REQUEST_TIME,CALL_START, CALL_END)) AS RowNumber
FROM [LogEntry] LE
)
SELECT *
FROM (Select *
FROM CallRowNum
WHERE [CALL START] IS NOT NULL) START
JOIN (SELECT *
FROM CallRowNum
WHERE [CallEnd] IS NOT NULL) [END]
ON [END].RowNumber = (START.RowNumber-1)
WHERE (START.[CALL START] IS NOT NULL
OR START.[CALL_REQUEST] IS NOT NULL
OR START.CallEnd IS NOT NULL)
到目前为止,我无法加入联接以拥有正确的呼叫请求,开始时间和结束时间。上面只是用来绑起和结束片
编辑-样本数据: