SELECT a.status, a.contract_id, a.product_id, b.num AS total , SUM(a.product_num - a.contract_outstock_num) AS sumNum FROM tableA a, tableB b
WHERE a.corpid = ? AND a.del = ? AND b.corpid = ? AND b.del = ? AND a.product_id = b.id AND a.is_produce = ? AND a.type = ?
GROUP BY a.contract_id, a.product_id
HAVING sumNum > total
ORDER BY a.id, a.product_id, a.contract_id
WHERE a.corpid = ? AND a.del = ? AND b.corpid = ? AND b.del = ? AND a.product_id = b.id AND a.is_produce = ? AND a.type = ?
GROUP BY a.contract_id, a.product_id
HAVING sumNum > total
ORDER BY a.id, a.product_id, a.contract_id