我有一个像这样的子查询
Select id,
sum(select fran_payment.amount
from fran_payment
where fran_payment.fran_id = id) as paid,
sum(select purchase.commission_amount
from purchase
where purchase.fran_id = id) as commission
from franchiese;
它在 select fran_ payment 附近给了我语法错误
最佳答案
您无法对查询求和。
您必须在查询中指定要求和的列,并且将返回此总和:
Select f.id,
(
select sum(fran_payment.amount)
from fran_payment
where fran_payment.fran_id = f.id
) as paid,
(
select sum(purchase.commission_amount)
from purchase
where purchase.fran_id = f.id
) as commission
from franchiese as f;
关于mysql - 更正 sum 函数语法错误中的子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57830085/