To begin, calculate the weight contribution of each of the records in the total amount across the table.
SELECT price, price / ( SELECT SUM(price) FROM balans) AS weight FROM balans
It is the weight that must be multiplied by the subtracted number 235 000 so that it is evenly distributed between all the records in the table.
SELECT price, 235000 * (price / ( SELECT SUM(price) FROM balans)) AS diff FROM balans
Now it only remains to subtract this value in the UPDATE . However, a normal UPDATE request will not work.
UPDATE balans SET price = price - 235000 * (price / ( SELECT SUM(price) FROM balans));
It is not allowed to specify the table 'balans' in the list of FROM tables to make changes to it
We'll have to make a multi-query. First, we create a multi-table query with the amount and value that you need to subtract from this amount.
SELECT balans.price AS original, 235000 * bcount.price / total.summ AS result FROM balans JOIN balans AS bcount ON balans.id = bcount.id JOIN (SELECT SUM(price) AS summ FROM balans) AS total
Now it’s not hard to make an UPDATE request.
UPDATE balans JOIN balans AS bcount ON balans.id = bcount.id JOIN (SELECT SUM(price) AS summ FROM balans) AS total SET balans.price = bcount.price - 235000 * bcount.price / total.summ
Now, if you count the sum of the columns, instead of 700,000, you get 465,000, just minus 235,000
SELECT SUM(price) FROM balans