UPDATE tabla SET campo3 = campo3 - campo2, campo2 = campo2 - campo1
DELIMITER // DROP PROCEDURE `changeVal`CREATE PROCEDURE `changeVal`() BEGIN DECLARE index INT DEFAULT 2; DECLARE rowCount INT; DECLARE oldVal INT; SET count = (SELECT COUNT(*) FROM tabla); WHILE (rowCount > index) DO SET oldVal = (SELECT valor FROM tabla WHERE id = rowCount-1); UPDATE tabla SET valor = valor - oldVal WHERE id = rowCount; SET rowCount = rowCount -1; END WHILEEND //
DELIMITER // DROP PROCEDURE `changeVal`CREATE PROCEDURE `changeVal`() BEGIN DECLARE index INT DEFAULT 2; DECLARE count INT; DECLARE oldVal INT; DECLARE myRow INT; SET count = (SELECT COUNT(*) FROM tabla); WHILE (count > index) DO SET oldVal = (SELECT valor FROM tabla LIMIT 1, count-2); SET myRow = (SELECT id FROM tabla LIMIT 1, count-1); UPDATE tabla SET valor = valor - oldVal WHERE id = myRow; SET count = count - 1; END WHILEEND //