在 sum 函数上无效使用 group 函数 [英] Invalid use of group function on sum function

查看:85
本文介绍了在 sum 函数上无效使用 group 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My SQL query is returning an error #1111 - Invalid use of group function when summing the rows on result

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

This Query is working fine and returning many rows.

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

我想对这些行求和,为此我使用了这个查询

I want to sum these rows, to do so I am using this query

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 - 组函数的使用无效

推荐答案

觉得不是group by的问题.试试

It think the problem is not the group by. Try

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

这篇关于在 sum 函数上无效使用 group 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆