我有下面的查询,我把它放在一起,它运行得很糟糕(我相信你可以看到)。
我很确定这与我转换日期时间的方式有关,以便我可以参考昨天的数据。
dtInteractionLocalStartTime 是一个日期时间字段,我希望它显示为 mm/dd/yyyy 而不是 yyyy-mm-dd hh:mm:ss.sss
关于如何优化它的任何想法?我已经花了过去 2 天,我无法弄清楚。
这是我的查询:
SELECT TOP 100 PERCENT
Date ,
CONVERT(varchar, VDN) AS VDN ,
COUNT(*) AS Calls ,
Avaya
FROM ( SELECT DISTINCT TOP 100 PERCENT
CONVERT(varchar,dtInteractionLocalStartTime,101) AS Date ,
vcVectorNumber AS VDN ,
iCompoundID ,
'CM03' AS Avaya
FROM NICEHUB3ADTM.nice_dw.dbo.vwNiceDBKitInteraction AS i
WHERE CONVERT(varchar(10) , dtInteractionLocalStartTime,101) = CONVERT(varchar(10),GETDATE()-1,101)
AND iMediaTypesId = 2
AND tiCallDirectionTypeID = 1
AND tiInteractionTypeID = 2
AND iInteractionOpenReasonID & 16 = 0
AND iInteractionOpenReasonID & 4 = 0
AND iInteractionID NOT IN ( SELECT iInteractionID
FROM NICEHUB3ADTM.nice_dw.dbo.vwException AS e
WHERE i.iInteractionID = iInteractionID
AND iExceptionTypeID IN (37, 12, 12310)
)
) AS derivedtbl_1
GROUP BY Date ,
CONVERT(varchar,VDN) ,
Avaya
ORDER BY Date ,
VDN