哪位大侠看看这段查询怎样改才能提高查询结果的速度,最好是不要用交叉连接,万分感谢(100分)

  • 主题发起人 主题发起人 bigness
  • 开始时间 开始时间
B

bigness

Unregistered / Unconfirmed
GUEST, unregistred user!
SELECT Product_1.s_ID as Prod_ID, a.Stor_ID, SUM(a.Prod_Number2) AS Prod_Number2, SUM(a.Prod_Number1)
AS Prod_Number1, convert(numeric(20,6) ,case when SUM(a.Prod_Number2) <> 0 then SUM(a.CostMoney) / SUM(a.Prod_Number2) else 0 end) AS CostPrice, SUM(a.CostMoney) AS CostMoney
FROM dbo.Product Product_1 CROSS JOIN
(SELECT Product.s_ID, Product.u_Code, Product.s_ParentID, s_FullID,
Stor_ID, SUM(StorageIni.Prod_Number1) AS Prod_Number1,
SUM(StorageIni.Prod_Number2) AS Prod_Number2,
SUM(CostMoney) CostMoney
FROM StorageIni INNER JOIN
Product ON StorageIni.Prod_ID = Product.s_ID
GROUP BY Product.s_ID, Product.u_Code, Product.s_ParentID,
Product.s_FullID, Stor_ID) a
WHERE (a.s_FullID LIKE Product_1.s_FullID + '%')
GROUP BY Product_1.s_ID, Product_1.u_Code, Product_1.u_Name,
Product_1.s_FullID, Product_1.ProdDW, Product_1.ProdSpec, Product_1.ProdType,
Product_1.ProdArea, Product_1.BarCode, a.Stor_ID
 
看得头晕了,你可以考虑使用临时表看看啊.
 
看的腦袋一蒙一蒙的
 
做个存储过程..大家都头晕了!
 
使用SQL server的分析器,找到瓶颈,建立索引。
治标不治本
 
后退
顶部