我搞砸了大事:我向 Phoca Gallery 添加了大约 2000 张图像,而不是将“标题”字段留空,所以它会使用文件名作为标题,我写下了类别的名称...重命名每个一个手动将是 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, '', '', '', '', '', '', '*'),
所以我会用每个图像的文件名替换“星期四,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 tablename
set
col1 = substring_index(col_file_path,'/',-1),
col2 = lower(substring_index(col_file_path,'/',-1));
关于mysql - 将 SQL 列的最后 N 个字符复制到另一列(也就是我搞砸了!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31177506/