If (1, 2, 3, 4, 4, 5)coming from a request SELECT id ..., you can do something like this:
UPDATE yourTable
JOIN
( SELECT id
, COUNT(id) AS counter
....
GROUP BY id
) AS data
ON yourTable.id = data.id
SET yourTable.field = yourTable.field + data.counter
;
Since the input comes from users, maybe you can manipulate it a bit. Change (1, 2, 3, 4, 4, 5)to (1), (2), (3), (4), (4), (5).
Then (by creating a temporary table):
CREATE TABLE tempUpdate
( id INT )
;
Perform the following procedure:
:
INSERT INTO TempUpdate
VALUES (1), (2), (3), (4), (4), (5)
;
UPDATE yourTable
JOIN
( SELECT id
, COUNT(id) AS counter
FROM TempUpdate
GROUP BY id
) AS data
ON yourTable.id = data.id
SET yourTable.field = yourTable.field + data.counter
;
DELETE FROM TempUpdate
;