答案 0 :(得分:1)
按产品对订单进行分组,以获得产品sum
- 列的pc
。
然后join
将product
汇总到pc
表格中,从product
表格中的SELECT
product.id_product,
(product.pc - ifnull(orders.amount, 0))
FROM
product
LEFT JOIN (
SELECT
id_product,
SUM(pc) AS amount
FROM
`Order`
GROUP BY
id_product
) AS orders ON orders.id_product = product.id_product
- 列中减去订单总和。
12,89,253 instead of 1,289,253