0

すべてのアイテムを取得するためのこのSQLがあります

SELECT A.item_code,A.description,A.uom, A.open_stock, B.recd_total, C.issue_qty
FROM chem_master as A
LEFT JOIN ( SELECT item_code, sum(recd_qty) as recd_total
from chem_reciepts GROUP BY item_code) as B on A.item_code=B.item_code
LEFT JOIN(SELECT item_code, sum(iss_qty) as issue_qty
from chem_issue GROUP BY item_code) as C on A.item_code=C.item_codeand 

返されるデータは

Item_code Description                      unit op.stock recd_total issue_qty

25139     ALUMINIUM OXIDE ACTIVE NEUTRAL   GM       0         0          0
54006     L-ASCORBIC ACID                  GM       0         0          0
AC001     ACETIC ACID GLACIAL              LTR      0         14         2
AC002     ACETONE AR                       LTR      0         0          0
AC005     ACACIA POWDER                    GM       0         0          0

私はそれらのレコードだけが欲しいopen_stock + recd_total - issue_qty = 0

SQLを変更するには?

4

3 に答える 3

2

havingクエリに(クエリの最後に)言及した条件を追加できます。
以下のようなもの:

HAVING op.stock+recd_total-issue_qty=0
于 2013-09-12T06:02:45.437 に答える
0

以下のクエリを使用

SELECT A.item_code,A.description,A.uom, A.open_stock, B.recd_total, C.issue_qty
FROM chem_master as A
LEFT JOIN ( SELECT item_code, sum(recd_qty) as recd_total
from chem_reciepts GROUP BY item_code) as B on A.item_code=B.item_code
LEFT JOIN(SELECT item_code, sum(iss_qty) as issue_qty
from chem_issue GROUP BY item_code) as C on A.item_code=C.item_codeand 
having op.stock+recd_total-issue_qty = 0;
于 2013-09-12T06:14:37.033 に答える