簡體   English   中英

我想更新mysql表column1,除非數據存在,然后移至下一個column2

[英]I want to update mysql table column1 unless data exists then move to next column2

我想更新我的MySQL表。 我想要做的就是更新column1除非存在數據column1然后將其移動到column2和更新一個來代替。 我當前擁有的代碼正在不斷更新第一列。

UPDATE users
SET    active = 1,
       time_started = '$_POST[in_time]'
WHERE  user_id = '$_POST[user_id]

有人可以幫忙嗎?

就像是:

update users set active=1, time_in_1=if(time_started is null,time_in_1,?), time_started=if(time_started is null,?,time_started) while ...

實際上,當time_started為null時,上述操作會執行以下操作:

update users set time_in_1=time_in_1, time_started=?

(保留time_in_1不變;?是您的新值的占位符)。 如果time_started不為null,則執行以下操作:

update users set time_in_1=?, time_started=time_started

(保持time_started不變)。 在這兩種情況下,您都需要提供兩次新值(假設只有一個;可能要將第二列更新為與將第一列更新為不同的值?)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM