2015-11-02 73 views
0

我寫了一個查詢(見圖片),其中顯示的結果如下圖所示。我要取總產品那些數量小於或等於零

現在,我想show那些product列表,其總可用quantity小於或equal to zero

我使用這個公式計算總的可用數量 -

(SUM(credit_quantity) - SUM(debit_quantity)) 

請檢查圖像顯示的數據庫表結構:

enter image description here

+1

你的圖像不見了? –

+1

你有任何代碼可以告訴我們嗎? – Nirnae

+0

您的「以下查詢」也缺失 –

回答

0

嘗試此查詢: -

SELECT * FROM nrk_product AS np LEFT JOIN 
nrk_stock AS ns ON np.id = ns.product_id GROUP BY np.id 
HAVING (SUM(ns.credit_quantity) - SUM(ns.debit_quantity)) <= 0 
+0

上面的SQL查詢給我一個空白的結果。請檢查小提琴 - http://sqlfiddle.com/#!9/51802/1 –

+1

它不給空白的結果。 – hd1

相關問題