1

I have this update query:

UPDATE
  account INNER JOIN c1
  ON c1.user = account.u_id
SET
  account.amount = account.amount + sum(c1.total_1)
WHERE
  t_ype =8 

but it returns Invalid Use Of Group Function... where is my mistake?

2 Answers 2

1

You need to do the aggregation before the join:

UPDATE account INNER JOIN
       (SELECT c1.user, sum(c1.total_1) as sumc
        FROM c1
        GROUP BY c1.user
       ) c1
       ON c1.user = account.u_id
    SET account.amount = account.amount + sumc
    WHERE account.t_ype = 8 ;
Sign up to request clarification or add additional context in comments.

Comments

1
UPDATE account 
JOIN 
(
  select user, sum(total_1) as sum_total
  from c1
  group by user
) c1 ON c1.user = account.u_id 
SET account.amount = account.amount + sum_total
WHERE account.t_ype = 8 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.