Question : Error - Invalid Use of Group Function

This is part of Multiple query and I am getting the above error:

Update inv i, (SELECT quantity, idservice, datetime FROM invitem) v, (SELECT charges, idservice FROM service) s
SET
  i.total = SUM(v.quantity * s.charges)
  WHERE s.idservice = v.idservice
  AND v.datetime = @uniquekey
  AND i.datetime = @uniquekey

Hope someone can point where the error is

Answer : Error - Invalid Use of Group Function

you cannot do like that indeed ...
http://www.experts-exchange.com/articles/Database/Miscellaneous/UPDATES-with-JOIN-for-everybody.html
mysql is unfortunately a bit limited in that regards, but you shall check out this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
Update inv i
SET i.total = ( select SUM(v.quantity * s.charges)
          from invitem v
          JOIN service s
             ON s.idservice = v.idservice
          WHERE v.datetime = i.datetime
            AND v.invoiceid = i.id  --- < I presume this link condition is missing also ...
       )
WHERE i.datetime = @uniquekey
Random Solutions  
 
programming4us programming4us