Reputation: 261
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
Result Image: 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
this is returning error #1111 - Invalid use of group function
Upvotes: 0
Views: 1624
Reputation: 1147
It think the problem is not the group by. Try
SUM( credit.Amount - COALESCE( creditreceived.Amount, 0 ) ) AS..
Upvotes: 1