SELECT m.inv_id,m.cus_id,CONCAT(c.customer_name ,', ', c.address) AS address,d.item_id,p.prod_name,d.quantity
FROM invoice_m m INNER JOIN customers c INNER JOIN invoice_d d INNER JOIN products p
WHERE m.cus_id = c.customer_id
AND m.inv_id = d.inv_id
AND d.item_id = p.prod_id
AND m.inv_id = 3
minus
SELECT m.inv_id,m.cus_id,m.cus_addr AS address,d.item_id,d.item_name AS prod_name,d.out_qty AS quantity
FROM delivery_m m INNER JOIN delivery_d d
WHERE m.inv_id = 3
我正在尝试执行MySQL减去查询无法正常工作。我需要减去(qty - out_qty)以便我可以获得实际的数量。
答案 0 :(得分:1)
MySQL不支持MINUS集合运算符。
所以像
这样的查询 SELECT x, y FROM table_a
MINUS
SELECT x, y FROM table_b;
在MySQL中成为:
SELECT a.x, a.y
FROM table_a a LEFT JOIN table_b b
ON a.x = b.x AND a.y = b.y
WHERE b.x IS NULL;