0
我需要一些幫助與此查詢MySQL的SUM CASE自加入
這是我的查詢
price received qty recieved price release qty release
10.30 10 0 0
0 0 10.30 2
0 0 10.30 1
19.20 20 0 0
0 0 19.20 5
0 0 19.20 3
0 0 19.20 1
的實際結果我的查詢中使用此代碼
$result = mysql_query("SELECT *,
SUM(CASE WHEN qtyreceived > 0 THEN qtyreceived END) AS qtyrec,
SUM(CASE WHEN qtyrelease > 0 THEN qtyrelease END) AS qtyrel
FROM stockledger
WHERE stockdesc= '$_POST[desc]' GROUP BY pricerelease,pricereceived ");
的結果是
價格收到qtyreceived價格釋放qtyrelease巴爾 10.30 10 10 19.20 20 20 10.30 3-3 19.20 9 -9
,我想查看結果這樣,所以我可以得到剩餘數量爲2倍的價格
price received qtyreceived price release qtyrelease bal
10.30 10 10.30 3 7
19.20 20 19.20 9 11
感謝.... 。
你怎麼會知道'10'將'加入-3'和'20'將'加入-9' ? – 2012-08-07 05:52:58
可以提供一些原始樣本數據嗎? – sel 2012-08-07 05:53:46