我正在使用的查询是:
SELECT
a.What_Tech,
a.callid FirstCallid,
b.Callid SecondCallid,
a.[segStart_dateTime] FirstCallTime,
b.[segStart_dateTime] SecondCallTime,
DateDiff(second, a.[segStart_dateTime], b.[segStart_dateTime]) as [myDiff]
FROM CallVolume.AreaGeneratedActivity a
JOIN CallVolume.AreaGeneratedActivity b on
a.calling_pty = b.calling_pty
and a.[segStart_dateTime] < b.[segStart_dateTime]
and dbo.getdateonly(a.segStart_dateTime) = dbo.getdateonly(b.segStart_dateTime)
WHERE ABS(DateDiff(second, a.[segStart_dateTime], b.[segStart_dateTime])) > 60
and ABS(DateDiff(second, a.[segStart_dateTime], b.[segStart_dateTime])) <= 1800
返回的是:
|What_Tech|FirstCallid|SecondCallid|FirstCallTime|SecondCallTime|myDiff | 技术1 | 21134601 | 21136023 | 09:19:41 | 09:20:43 | 62 | 技术1 | 21134601 | 21134507 | 09:19:41 | 09:19:41 | 886 | 技术1 | 21134601 | 21134602 | 09:19:41 | 09:34:27 | 887
我想要的是不同的FirstCallids:
|What_Tech|FirstCallid|SecondCallid|FirstCallTime|SecondCallTime|myDiff | 技术1 | 21134601 | 21134676 | 09:19:41 | 09:20:43 | 62 | 技术1 | 21136023 | 21136024 | 09:34:27 | 09:35:27 | 1
以下是表中的一些示例数据:
INSERT [dbo].[TestData](callid, What_Tech, segStart_dateTime, segStop_dateTime, duration)
SELECT 21134601, N'Tech1', '20120307 09:19:41', '20120307 09:20:35', 54 UNION ALL
SELECT 21134676, N'Tech1', '20120307 09:20:43', '20120307 09:21:30', 47 UNION ALL
SELECT 21136023, N'Tech1', '20120307 09:34:27', '20120307 09:36:54', 147 UNION ALL
SELECT 21148838, N'Tech1', '20120307 12:00:29', '20120307 12:02:05', 96 UNION ALL
SELECT 21149159, N'Tech1', '20120307 12:04:32', '20120307 12:05:46', 74 UNION ALL
SELECT 21163170, N'Tech1', '20120307 14:50:08', '20120307 14:52:36', 148
请注意,返回的示例数据和我想要的只是示例,而不是直接来自 INSERT 语句中给出的示例数据
calling_party
发布的查询(一旦我删除了缺少的连接条件INSERT
并将函数调用更改为内联计算)在给定提供的示例数据的情况下产生这些结果:
What_Tech FirstCallId SecondCallId FirstCallTime SecondCallTime myDiff
--------- ----------- ------------ ------------------- ------------------- ------
Tech1 21134601 21134676 2012-03-07 09:19:41 2012-03-07 09:20:43 62
Tech1 21134601 21136023 2012-03-07 09:19:41 2012-03-07 09:34:27 886
Tech1 21134676 21136023 2012-03-07 09:20:43 2012-03-07 09:34:27 824
Tech1 21148838 21149159 2012-03-07 12:00:29 2012-03-07 12:04:32 243
鉴于此,您能否根据您提供的实际样本数据定义您期望的结果,而不是从我们看不到的一组略有不同的数据中显示所需的结果?