[英]Copy last N characters of SQL column in another column (AKA I messed up!)
我搞砸了很多時間:我在Phoca Gallery中添加了大約2000張圖像,而不是將“ title”字段留為空白,因此它將文件名用作標題,我寫下了類別的名稱...手動重命名每個類別成為PITA,但我確信可以用SQL完成,除非我真的不知道如何做。
我現在所擁有的是:
(15574, 1379, 0, 'Thursday, 25.6.', 'thursday-25-6', 'competitions/hrprvprj/25.6/120/vucemilo_filip/_MG_5545.jpg', 1, NULL, '2015-07-01 16:55:11', 0, '', '', 0, '', 0, NULL, 0, 212111, 1, 1, 0, '0000-00-00 00:00:00', 13, NULL, NULL, NULL, NULL, NULL, NULL, '', 0, '', '', '', '', '', '', '*'),
我需要的是:
(15574, 1379, 0, '_MG_5545.jpg', '_mg_5545.jpg', 'competitions/hrprvprj/25.6/120/vucemilo_filip/_MG_5545.jpg', 1, NULL, '2015-07-01 16:55:11', 0, '', '', 0, '', 0, NULL, 0, 212111, 1, 1, 0, '0000-00-00 00:00:00', 13, NULL, NULL, NULL, NULL, NULL, NULL, '', 0, '', '', '', '', '', '', '*'),
因此,我將“ Thursday,25.6”替換為別名“ thursday-25-6”,並將其替換為每張圖片的文件名,這是圖片位置所在列的最后12位數字。
我可以在phpMyAdmin中輸入任何可以解決問題的字符串嗎?
非常感謝!
如果模式相同,即competitions/hrprvprj/25.6/120/vucemilo_filip/_MG_5545.jpg'
則可以使用substring_index
函數,使用該函數不必依賴12 characters
而是可以提取字符串后的最后一部分最后/
作為
mysql> select substring_index('competitions/hrprvprj/25.6/120/vucemilo_filip/_MG_5545.jpg','/',-1) as i ;
+--------------+
| i |
+--------------+
| _MG_5545.jpg |
+--------------+
1 row in set (0.00 sec)
mysql> select lower(substring_index('competitions/hrprvprj/25.6/120/vucemilo_filip/_MG_5545.jpg','/',-1)) as i ;
+--------------+
| i |
+--------------+
| _mg_5545.jpg |
+--------------+
1 row in set (0.00 sec)
因此,您可能將update命令作為
update tablename
set
col1 = substring_index(col_file_path,'/',-1),
col2 = lower(substring_index(col_file_path,'/',-1));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.