Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Use of group function

Status
Not open for further replies.

bxgirl

Programmer
Nov 21, 2005
75
US
Using mysql 4.0

I get the following error message

"Invalid Use of group function"

with the following code:

update custRP c, tbl_acctbal a
set c.rpBal = sum(a.currRPBAL)
where c.custid = a.custid

Why?
 
In order to use a SUM clause you must group by the rows in that column or you can't use the SUM clause.

so add GROUP BY a.currRPBAL to the last line of your query.
 
actually you won't want to group by that field necessarily, you will need to figure out which column you need to group by.
 
Your suggestion didn't work.

This is the table I want to update

create temporary table custRP(
custid int,
rpBal int)

The update code:

update custRP c, tbl_acctbal a
set c.rpBal = sum(a.currRPBAL)
where c.custid = a.custid
group by custRP.custid

Adding the group by doesn't work. I get the following error message "you have an error in your sql syntax..."

 
When posting an error message it is helpful to post the entire message, they mean different things when you can see the entire message.

I can tell you why you are getting this specific error though, you can't refer to the table custRP in your group by clause since you have given your table an alias.

more importantly though, can you show some sample rows of both tables and it might clear up exactly what you are tryingto do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top