- 论坛徽章:
- 0
|
两个大表
tblSaleUnit:StoreID,ItemID,salesunit
tblPrice: StoreID,ItemID,salesprice
要获得各店的 sales value.需要将两表通过StoreID,itemID连接,
最简单的就是:
select tblSaleUnit.StoreID,sum(salesunit * salesprice) from tblSaleUnit,tblPrice
where tblSaleUnit.StoreID=tblPrice.StoreID
and tblSaleUnit.ItemID=tblPrice.ItemID
group by tblSaleUnit.StoreID;
或者先建一个临时表tblTmp
select tblSaleUnit.StoreID,salesunit , salesprice into tblTmp from tblSaleUnit,tblPrice
where tblSaleUnit.StoreID=tblPrice.StoreID
and tblSaleUnit.ItemID=tblPrice.ItemID;
然后再在tblTmp 上作Group 操作.
试问哪种方法更快? |
|