我有一个相对简单的查询连接两个表。 “Where”标准可以在连接标准中或作为where子句表达。我想知道哪个更有效率。SQL在连接条件或where子句中过滤标准更有效
查询是从推销员开始直到他们晋升为止,找到推销员的最大销售额。
案例1
select salesman.salesmanid, max(sales.quantity)
from salesman
inner join sales on salesman.salesmanid =sales.salesmanid
and sales.salesdate < salesman.promotiondate
group by salesman.salesmanid
案例2
select salesman.salesmanid, max(sales.quantity)
from salesman
inner join sales on salesman.salesmanid =sales.salesmanid
where sales.salesdate < salesman.promotiondate
group by salesman.salesmanid
注案例1缺少where子句完全
RDBMS是SQL Server 2005中
编辑 如果第二一片连接标准或where子句是sales.salesdate <某个固定的日期,所以它实际上没有任何加入两个表的标准确实会改变答案。
实际测试这些查询所花费的时间有什么问题? – ChristopheD 2009-09-09 20:30:00
因为查询的get缓存,但感谢,真的 – Gratzy 2009-09-09 20:35:29
@Gratzy - DBCC FREEPROCCACHE http://msdn.microsoft.com/en-us/library/ms174283.aspx – 2009-09-09 20:48:38