关于sql server查询的问题

DECLARE @City NVARCHAR(20);
SET @City='London';
SELECT C.CustomerID,COUNT(O.OrderID) AS NumOrders FROM dbo.Customers AS C
LEFT JOIN dbo.Orders AS O
ON C.CustomerID=O.CustomerID
WHERE C.City=@City
GROUP BY C.CustomerID
HAVING COUNT(O.OrderID)>5
ORDER BY NumOrders

SELECT C.CustomerID,COUNT(O.OrderID) AS NumOrders FROM dbo.Customers AS C
LEFT JOIN dbo.Orders AS O
ON C.CustomerID=O.CustomerID
WHERE C.City='London'
GROUP BY C.CustomerID
HAVING COUNT(O.OrderID)>5
ORDER BY NumOrders

 

为什么使用变量之后,第一个快过第二个,

第一个的执行开销为43%

第二个的执行开销为57%

白猪掌柜的
浏览 508回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server