- 假设样本记录显示CompanyName,CompanyID,OrderID,Ordername,Sum(Amount)。除了所有列都是Varchar
CompanyName | CompanyID | OrderID | OrderName | Amount
CS | 10 | 5567 | Bonds | 67000
CS | 10 | 5567 | Bonds | 77000
CS | 10 | 5566 | Derivatives | 90000
Barleys | 20 | 5567 | Bonds | 90000
Barleys | 20 | 5566 | Derivatives | 90000
T.D | 30 | 5566 | Derivatives | 90000
T.D | 30 | 5567 | Bonds | 60000
哪种查询效率高
Select CompanyName, CompanyID, OrderID, OrderName ,Sum(Amount)
from @Table
group by CompanyName, CompanyID, OrderID, OrderName;
或者:
Select CompanyID, Max(CompanyName),OrderID, Max(OrderName) ,Sum(Amount)
from @Table
group by CompanyID, OrderID;
如果表包含超过700万条记录,那么两个查询都会给出相同的结果但是知道哪个查询在性能方面是好的。该组会影响表现吗?