gpt4 book ai didi

mysql - 对 sum 函数使用 group 函数无效

转载 作者:行者123 更新时间:2023-11-29 11:43:17 24 4
gpt4 key购买 nike

My SQL 查询返回错误#1111 - 对结果中的行求和时组函数的无效使用

此查询工作正常并返回许多行。

SELECT credit.Amount - SUM( COALESCE( creditreceived.Amount, 0 ) ) AS 
AmountReceivable FROM credit LEFT JOIN creditreceived ON credit.ID =
creditreceived.CreditID WHERE credit.CompanyID = '1' GROUP BY credit.id

结果图像: http://oi65.tinypic.com/qplyli.jpg

我想对这些行求和,为此我正在使用此查询

SELECT SUM( credit.Amount - SUM( COALESCE( creditreceived.Amount, 0 ) ) ) AS
AmountReceivable FROM credit LEFT JOIN creditreceived ON credit.ID =
creditreceived.CreditID WHERE credit.CompanyID = '1' GROUP BY credit.id

这将返回错误#1111 - 组函数的使用无效

最佳答案

它认为问题不在于分组依据。尝试一下

SUM(credit.Amount - COALESCE(creditreceived.Amount, 0 ) ) AS..

关于mysql - 对 sum 函数使用 group 函数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35390845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com