SQL - 用条件替换另一列值的列值

时间:2017-05-22 14:16:57

标签: mysql database wordpress woocommerce

好的,说得很清楚, 我的表看起来像这样:

ID          post_title                      post_type
------------------------------------------------------
1           product A                       product
2           product A - Size S              product_variation
3           product A - Size M              product_variation
4           product A - Size L              product_variation
5           product B                       product
6           product A - Size S              product_variation
7           product A - Size M              product_variation
8           product A - Size L              product_variation
9           product C                       product
10          product A - Size S              product_variation
11          product A - Size M              product_variation
12          product A - Size L              product_variation
13          product D                       product
14          product A - Size S              product_variation
15          product A - Size M              product_variation
16          product A - Size L              product_variation

我想要像这样:

ID          post_title                      post_type
------------------------------------------------------
1           product A                       product
2           product A - Size S              product_variation
3           product A - Size M              product_variation
4           product A - Size L              product_variation
5           product B                       product
6           product B - Size S              product_variation
7           product B - Size M              product_variation
8           product B - Size L              product_variation
9           product C                       product
10          product C - Size S              product_variation
11          product C - Size M              product_variation
12          product C - Size L              product_variation
13          product D                       product
14          product D - Size S              product_variation
15          product D - Size M              product_variation
16          product D - Size L              product_variation

如何将post_type“product”的值更改为“product_variation”的值post_title作为父级。

如果我有大约1000个产品,我该怎么改变它??

1 个答案:

答案 0 :(得分:0)

你可以使用替换功能

update tableName set post_title=REPLACE(post_title,'A','B') where ID in(6,7,8)