答案 0 :(得分:2)
您可以先执行JOIN
,然后再进行求和:
SELECT p.code, SUM(p.price) price_total, SUM(s.total) sale_total
FROM Produce p INNER JOIN
(SELECT ID, SUM(salesoff) as total
FROM Sale s
GROUP BY ID
) s
ON s.ID = p.id
GROUP BY p.code;