我试图了解如何用不同的值更新多行,但我不明白。解决方案无处不在,但对我来说似乎很难理解。
例如,将三个更新更新为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';
我读了一个例子,但是我真的不明白如何进行查询。即:
UPDATE table_to_update
SET cod_user= IF(cod_office = '17389551','622057','2913659','6160230')
,date = IF(cod_office = '17389551','12082014')
WHERE ?? IN (??) ;
如果在WHERE和IF条件中存在多个条件,我还不太清楚如何执行查询。
这回答了你的问题了吗?MySQL中的多个更新
—
PeterPan666