问题:
I am trying to understand how to UPDATE multiple rows with different values and I just don't get it.我试图了解如何使用不同的值更新多行,但我不明白。 The solution is everywhere but to me it looks difficult to understand.解决方案无处不在,但对我来说似乎很难理解。
For instance, three updates into 1 query:例如,三个更新为 1 个查询:
UPDATE table_users
SET cod_user = '622057'
, date = '12082014'
WHERE user_rol = 'student'
AND cod_office = '17389551';
UPDATE table_users
SET cod_user = '2913659'
, date = '12082014'
WHERE user_rol = 'assistant'
AND cod_office = '17389551';
UPDATE table_users
SET cod_user = '6160230'
, date = '12082014'
WHERE user_rol = 'admin'
AND cod_office = '17389551';
I read an example, but I really don't understand how to make the query.我读了一个例子,但我真的不明白如何进行查询。 ie: IE:
UPDATE table_to_update
SET cod_user= IF(cod_office = '17389551','622057','2913659','6160230')
,date = IF(cod_office = '17389551','12082014')
WHERE ?? IN (??) ;
I'm not entirely clear how to do the query if there are multiple condition in the WHERE and in the IF condition..any ideas?如果 WHERE 和 IF 条件中有多个条件,我不完全清楚如何进行查询..有什么想法吗?
解决方案:
参考一: https://en.stackoom.com/question/1jjAf参考二: https://stackoom.com/question/1jjAf