[英]MySQL update column and return value from another column in the same table
[英]Update Column from another column in same table
我們需要在表格中更新我們的郵件地址,因為我們有一個新的域名部分。 當地部分保持不變
在表中是Name,Surname和Mail的列。 (和其他不重要的列)。
我們希望它最終看起來像這樣:
Name Surname Mail
Test Name Test.Name@newdomain.com
Test2 Name2 Test2.Name2@newdomain.com
但是在嘗試這樣做時我們打破了它,現在郵件列只顯示了新域。 我們使用以下代碼:
update table
set mail = Replace('olddomain.com','newdomain.com')
where mail LIKE '%olddomain.com'
所以現在我們需要恢復郵件列並添加新的域部分。 有幫助嗎?
我很驚訝這個作品。 通常, replace()
有三個參數:
set mail = Replace(mail, 'olddomain.com', 'newdomain.com')
我可能會建議您在邏輯中包含@
。
replace()接受三個參數
update table
set mail = Replace(mail,'@olddomain.com','@newdomain.com')
where mail LIKE '%olddomain.com'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.