我想在mysql数据库中找到并重命名,我这样命令:
UPDATE wp_postmeta
SET meta_id = REPLACE(meta_id, "-SITE-", "-SITE-.mkv"),
post_id = REPLACE(post_id, "-SITE-", "-SITE-.mkv"),
meta_key = REPLACE(meta_key, "-SITE-", "-SITE-.mkv"),
meta_value = REPLACE(meta_value, "-SITE-", "-SITE-.mkv")
我需要将所有" -SITE- "
重命名为" -SITE-.mkv "
,只需将.mkv
扩展名添加到" -SITE- "
,但此处存在问题。
在执行此操作之前,我们的表中还有另一个"-SITE-.mkv"
。如果我想搜索-SITE-
,此命令会将旧参数重命名为-SITE-.mkv.mkv
。
如何在END处找到并重命名只有.mkv
的参数?
我只需要在没有-SITE-
的情况下找到.mkv
并在结尾添加.mkv
。
任何人都可以帮助我?
谢谢
答案 0 :(得分:1)
您只需要包含WHERE
子句,并可以选择将其与NOT LIKE '%value%
结合使用。百分号是外卡,并且因为您只对以.mkv结尾的列感兴趣,所以您只需要第一个在.mkv之前包含任何内容。
为了使它更清晰,我将您的查询分成四个语句。
UPDATE wp_postmeta SET meta_id = REPLACE(meta_id, "-SITE-", "-SITE-.mkv") WHERE meta_id NOT LIKE '%.mkv';
UPDATE wp_postmeta SET post_id = REPLACE(post_id, "-SITE-", "-SITE-.mkv") WHERE post_id NOT LIKE '%.mkv';
UPDATE wp_postmeta SET meta_key = REPLACE(meta_key, "-SITE-", "-SITE-.mkv") WHERE meta_key NOT LIKE '%.mkv';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, "-SITE-", "-SITE-.mkv") WHERE meta_value NOT LIKE '%.mkv';
答案 1 :(得分:1)
您可以将查询分解为多个查询
UPDATE wp_postmeta SET meta_id = REPLACE(meta_id, "-SITE-", "-SITE-.mkv") WHERE meta_id ='-SITE-';
UPDATE wp_postmeta SET post_id = REPLACE(post_id, "-SITE-", "-SITE-.mkv") WHERE post_id ='-SITE-';
UPDATE wp_postmeta SET meta_key = REPLACE(meta_key, "-SITE-", "-SITE-.mkv") WHERE meta_key ='-SITE-';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, "-SITE-", "-SITE-.mkv") WHERE meta_value ='-SITE-';