我想减去两个数字,一个是字段的内容,另一个是查询结果的总和,我该怎么做?这显示了我想要的,但显然不起作用,该怎么办?
SELECT monto FROM programaPago WHERE id=2
**MINUS**
SELECT SUM( caja.monto ) FROM caja WHERE caja.programaPago_id =2
最佳答案
尝试这个:
SELECT ( programaPago.monto - COALESCE(iTotal.TotalMonto,0)) Result
FROM programaPago LEFT JOIN
(SELECT programaPago_id, SUM(monto) as TotalMonto
FROM caja GROUP BY programaPago_id) as iTotal
ON programaPago.ID = iTotal.programaPago_id
WHERE programaPago.ID = 2
关于mysql - 如何从mysql中两次选择的结果中减去,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9155230/