provalo usa il valore di aggiornamento da left join
(somma + conteggio)
update T T1
left join (
select `user`,sum(`sales`) newtotal,count(`order`) neworders
from T
group by `user`
) T2 on T1.`user` = T2.`user`
set T1.total = T2.newtotal,T1.orders = T2.neworders
Test DDL:
CREATE TABLE T
(`user` varchar(4), `sales` int, `order` varchar(7), `total` int, `orders` int)
;
INSERT INTO T
(`user`, `sales`, `order`, `total`, `orders`)
VALUES
('xx01', 100, 'order01', 0, 0),
('xx02', 200, 'order02', 0, 0),
('xx02', 400, 'order03', 0, 0),
('xx03', 300, 'order04', 0, 0),
('xx03', 500, 'order05', 0, 0)
;
Risultato:
| user | sales | order | total | orders |
|------|-------|---------|-------|--------|
| xx01 | 100 | order01 | 100 | 1 |
| xx02 | 200 | order02 | 600 | 2 |
| xx02 | 400 | order03 | 600 | 2 |
| xx03 | 300 | order04 | 800 | 2 |
| xx03 | 500 | order05 | 800 | 2 |