SELECT ss.quan FROM `stock` as ss
JOIN `order_record` as r ON r.order_id = ss.order_id
WHERE ss.from = 'c'
AND r.from = 'c'
AND r.status = 'ing'
AND ss.prod_id = 120
GROUP BY ss.order_id
這是從數據庫撈出的:
這個數字是沒問題的但是當我改成這樣
SELECT sum(ss.quan) as num FROM `stock` as ss
JOIN `order_record` as r ON r.order_id = ss.order_id
WHERE ss.from = 'c'
AND r.from = 'c'
AND r.status = 'ing'
AND ss.prod_id = 120
// GROUP BY ss.order_id
數字變成了 32
如果加入 GROUP BY ss.order_id 一樣是 32這很明顯有五個不同的 order_id
這可能各位會很難理解我只是想問說明明一開始數字是對的當 sum 後就不對了當使用 sum 要注意什麼事情?不能這樣直接 sum ?
- 2 回答
- 0 关注
- 386 浏览
添加回答
举报
0/150
提交
取消