我搞砸了:我向Phoca Gallery添加了大约2000张图片,而不是将" title“字段留空,这样它就会使用文件名作为标题,我写下了类别的名称……手动重命名每一个都很麻烦,但我确信它可以用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”和它的别名“星期四-25-6”替换为每个图像的文件名,这是包含图像位置的列的最后12位数字。
有没有什么字符串可以让我在phpMyAdmin中输入呢?
非常感谢!
发布于 2015-07-02 15:03:20
如果模式是相同的,即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));发布于 2015-07-02 15:04:06
您可以使用substring函数提取字符串的最后12个字符,然后它就是一个普通的旧update了
UPDATE mytable
SET title = SUBSTRING(filename, -12),
alias = LOWER(SUBSTRING(filename, -12))
WHERE <some condition>https://stackoverflow.com/questions/31177506
复制相似问题