![](/img/trans.png)
[英]MySQL - populating a column with a substring from another column in the same row
[英]Replace substring in one column with value from another column in same row
我有一個MySQL數據庫,其中有兩列, id
和file
:
id file
1 /img/333.PNG
2 /img/452645.jpg
3 /img/1.gif
file
都具有相同的路徑( /img/
),數字和圖形文件擴展名,其中一些位於小寫( .png
)中,而某些則大寫( .JPEG
)。
file
與id
(來自同一行)? 以上示例的結果應類似於:
id file
1 1.PNG
2 2.jpg
3 3.gif
筆記:
file
。 這應該工作
UPDATE table SET file = CONCAT(id, '.', RIGHT(file, 3));
要容納JPEG擴展名,請找到點的位置。
UPDATE table SET file = CONCAT(id, SUBSTRING(file, POSITION('.' IN file)));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.