|
SELECT Stock.GoodsID, Goods.GoodsName,
Goods.NormalPrice, SUM (Stock.Stock) AS Stock,
(SUM (Stock.Stock) * Goods.NormalPrice) AS allMoney
FROM Stock, Goods WHERE Stock.GoodsID = Goods.GoodsID
GROUP BY Stock.GoodsID, Goods.GoodsName, Goods.NormalPrice, Stock
The above is correct.I just add a condition and write:
SELECT Stock.GoodsID, Goods.GoodsName,
Goods.NormalPrice, SUM (Stock.Stock) AS Stock,
(SUM (Stock.Stock) * Goods.NormalPrice) AS allMoney
FROM Stock, Goods WHERE Stock.GoodsID = Goods.GoodsID AND Stock <3
GROUP BY Stock.GoodsID, Goods.GoodsName, Goods.NormalPrice, Stock
After writing this, the inventory quantity found is wrong, what's going on ?!
The structure of the STOCK table is:
ID, GoodsID, WarehouseID, Stock
The above STOCK table may have the same GOODSID but different WAREHOUSEID, I think the problem may be here. For example:
ID GoodsID WarehouseID Stock
1 g1 w1 10
2 g1 w2 5
Thank you! |
|