問題:
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