首页 新闻 会员 周边 捐助

关于sql server查询的问题

0
悬赏园豆:10 [已解决问题] 解决于 2015-03-24 22:37
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%

学弱的主页 学弱 | 初学一级 | 园豆:54
提问于:2015-03-23 23:14
< >
分享
最佳答案
0
收获园豆:10
邀月 | 高人七级 |园豆:25475 | 2015-03-24 00:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册