A
A
Alex Lav2020-02-22 22:01:11
MySQL
Alex Lav, 2020-02-22 22:01:11

How to change value in MySQL table if...?

How to change the value of the dle_users table, the balance column, depending on the value of the user_group column
That is, if the value of the user_group column = 3, then the value of the balance column should be added the number 10
If the value of the user_group column = 4, then the value of the balance column should be added the number 40. The value in the balance column can be anything and a number must be added to it depending on the number in the user_group column.
Thanks in advance for your help in resolving this issue.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sviridov, 2020-02-22
@aleks78888

Try like this:

UPDATE mytable
SET balance =
    (
        CASE
            WHEN user_group  = 3 THEN balance + 10
            WHEN user_group  = 4 THEN balance + 40
        END
    )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question