【发布时间】:2010-12-15 00:51:48
【问题描述】:
SELECT
tba.UpdatedDate AS UpdatedDate,
tsh.SupplierID,
ts.ProductCode as ProductCode,
sum(tba.AfterDiscount) as AfterDiscount,
sum(tba.Quantity) as Quantity
FROM
tblstockhistory as tsh
left join tblstock as ts
on tsh.StockID=ts.StockID
left join tblbasket as tba
on ts.ProductCode=tba.ProductCode
and tsh.SupplierID=49
AND tba.Status=3
group by
tba.UpdatedDate
ORDER BY
Quantity DESC
我有供应商表,供应商 id 标记到 tblstockhistory 表中,在这个 tblstockhistory 表中包含 StockID(来自 tblstock 表的引用),我有 Stock 表包含 StockID、ProductCode、 我有 tblbasket 表,在此维护 ProductCode,
我的想法在这里, 我想按供应商 ID 显示 thw 统计信息,当我传递供应商 ID 时,它会显示显示,该供应商提供的商品销售统计信息,
但上面的查询有时会返回空值,执行时间太长,大约50秒,
我从上面的查询中得到下面的东西
Date SupplierID, Amount, Quantity
2010-12-12 12 12200 20
2010-12-12 40 10252 30
2010-12-12 10 12551 50
2010-12-13 22 1900 20
2010-12-13 40 18652 30
2010-12-13 85 19681 50
2010-12-15 22 1900 20
2010-12-15 40 18652 30
2010-12-15 85 19681 50
【问题讨论】:
-
为了提高性能,请确保您在连接中使用的所有字段都已编入索引。