我正在尝试使我们的应用程序发送的查询更有效。我稍微修改了 SSMS 中的查询,它将在大约 1 秒内执行。
查询 A
SELECT O.Code AS 'Code', O.[Action] AS 'Action',
SUM(OpenResponseWithin) AS 'OpenResponseWithin',
CONVERT(VARCHAR,convert(decimal(10,2),(((SUM(OpenResponseWithin))*100))/convert(decimal(10,2),(SUM(OpenResponseWithin)+SUM(OpenResponseAfter))))) + '%' AS 'OpenResponseWithinPercentage',
SUM(OpenResponseAfter) AS 'OpenResponseAfter',
CONVERT(VARCHAR,convert(decimal(10,2),(((SUM(OpenResponseAfter))*100))/convert(decimal(10,2),(SUM(OpenResponseWithin)+SUM(OpenResponseAfter))))) + '%' AS 'OpenResponseAfterPercentage',
(SUM(OpenResponseWithin)+SUM(OpenResponseAfter)) AS 'OpenTotal',
SUM(CloseResponseWithin) AS 'CloseResponseWithin',
CONVERT(VARCHAR,convert(decimal(10,2),(((SUM(CloseResponseWithin))*100))/convert(decimal(10,2),(SUM(OpenResponseWithin)+SUM(OpenResponseAfter))))) + '%' AS 'CloseResponseWithinPercentage',
SUM(CloseResponseAfter) AS 'CloseResponseAfter',
CONVERT(VARCHAR,convert(decimal(10,2),(((SUM(CloseResponseAfter))*100))/convert(decimal(10,2),(SUM(OpenResponseWithin)+SUM(OpenResponseAfter))))) + '%' AS 'CloseResponseAfterPercentage',
SUM(CloseNever) AS 'CloseNever',
CONVERT(VARCHAR,convert(decimal(10,2),(((SUM(CloseNever))*100))/convert(decimal(10,2),(SUM(OpenResponseWithin)+SUM(OpenResponseAfter))))) + '%' AS 'CloseNeverPercentage'
FROM Custom_OpenCodeMRC O
WHERE O.ActionDate BETWEEN '10/5/2017' AND '12/4/2017'
AND
O.Code IN ('BERZ20','BERZ21','BERZ24','BERZ50','FTHZ63','YOR56','YOR57')
GROUP BY O.Code,O.[Action]
ORDER BY O.Code,O.[Action]
Run Code Online (Sandbox Code Playgroud)
如果我按照应用程序通过参数传入的方式保留查询,则执行至少需要 20 秒。
查询 …