分组代码

时间:2018-01-14 11:32:43

标签: sql sql-server

我遇到了根据相应的总结代码将数据分组的挑战。

我有一个看起来像截图A的视图,我的尝试导致截图B实际上我的结果需要返回截图C.

简而言之,我需要将NULLS分组到SegmentType Interact + hold + wrap组成一个调用的相应最终结果

提前为帖子格式道歉。

屏幕截图A

vw_Conversations

屏幕截图B

Query Result

屏幕截图C

Desired Output

Code Examaple

SELECT TOP 1000
  vw_Conversations.direction
 ,vw_Conversations.conversationId
 ,vw_Conversations.username
 ,vw_Conversations.conversationStart
 ,vw_Conversations.wrapUpCode
 ,DATEDIFF_BIG(MILLISECOND, vw_Conversations.segmentStart, vw_Conversations.segmentEnd) AS Duration

FROM dbo.vw_Conversations

WHERE vw_Conversations.purpose = 'user'
OR vw_Conversations.purpose = 'agent'
AND vw_Conversations.segmentType <> 'alert'

  GROUP BY vw_Conversations.direction
        ,vw_Conversations.username
        ,vw_Conversations.wrapUpCode
        ,vw_Conversations.conversationStart
        ,DATEDIFF_BIG(MILLISECOND, vw_Conversations.segmentStart, vw_Conversations.segmentEnd)
        ,vw_Conversations.conversationId

0 个答案:

没有答案