Если вы хотите обновить таблицу в базе данных, вы можете сделать это:
create table newtable
(`cartid` int, `prodid` int unique key, `quantity` int);
insert into newtable
select * from yourtable order by cartid
on duplicate key update quantity=newtable.quantity+values(quantity)
select * from newtable
Вывод:
cartid prodid quantity
1 9226582 8
3 7392588 1
Если вы довольны результатом, вы можете тогда
drop table yourtable
alter table newtable rename to yourtable