gpt4 book ai didi

mysql - 更正 sum 函数语法错误中的子查询

转载 作者:行者123 更新时间:2023-11-29 06:28:44 27 4
gpt4 key购买 nike

我有一个像这样的子查询

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/

27 4 0
文章推荐: mysql - 调用存储过程后MySQL存储过程的OUT参数为空
文章推荐: java - 无法理解 PriorityQueue 如何改变排序顺序?
文章推荐: java - 使用 java 流将 Stream 转换为 List