declare @begin datetime,@end datetime,@typeid int,@bumenid int
set @begin='2013-3-1'
set @end='2013-4-10'
set @bumenid=2
set @typeid=60
select isnull(sum(profit),0) as lirun
from
(
SELECT pf.Profit, ospd.orderid, ospd.Type, ospd.typeid, ospd.Sort, ospd.sortid, ospd.[Group], ospd.groupid, ospd.Brand, ospd.brandid,
ospd.ProductID, ospd.Model, ospd.Quantity, ospd.Price, ospd.BuMenID, ospd.OrderTime
FROM dbo.View_OrderSaleProductDetail1 AS ospd INNER JOIN
dbo.tb_OrderSale AS os ON os.ID = ospd.ordersaleid LEFT OUTER JOIN
dbo.tb_f_Ledger AS l ON l.OrderID = os.OrderID AND l.OperationID = 1 LEFT OUTER JOIN
dbo.tb_f_c_Profit AS pf ON pf.LedgerID = l.ID AND pf.ProductID = ospd.ProductID
)
as
aaa
where
ordertime between @begin and @end and bumenid=@bumenid and typeid=@typeid
我想得到的是 某个部门,某个大分类在制定时间段内的销售统计数据【销售数量,利润,总金额】
但是非常奇怪的是,现在表里面只有6000条数据,但是非常慢
能到14秒才加载出数据。
而且,如果
我把 isnull(sum(profit),0) as lirun 换了就很快
或者是 我把where 中的bumenid=@bumenid 限制去掉或是
and typeid=@typeid 其中之一去掉就很快...