且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL-在一个查询中更新具有不同值的多行

更新时间:2023-01-30 15:16:07

您可以这样做:

UPDATE table_users
    SET cod_user = (case when user_role = 'student' then '622057'
                         when user_role = 'assistant' then '2913659'
                         when user_role = 'admin' then '6160230'
                    end),
        date = '12082014'
    WHERE user_role in ('student', 'assistant', 'admin') AND
          cod_office = '17389551';

我不了解您的日期格式.日期应使用本机日期和时间类型存储在数据库中.

I don't understand your date format. Dates should be stored in the database using native date and time types.