Mysql 在求和函数语法错误中更正子查询

Mysql 在求和函数语法错误中更正子查询,mysql,subquery,Mysql,Subquery,我有一个子查询,比如 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

我有一个子查询,比如

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 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;

不能对查询求和。
您必须在查询中指定要求和的列,并且将返回此总和:

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;

我应该在发帖前多喝点咖啡。。。如果你想问的话,这里有一个答案。我应该在发帖前多喝点咖啡。。。如果你想查询的话,这里有一个答案。