2017-05-22 75 views
0

OK使其很清楚, 我有表如下所示:SQL - 從另一列值替換列的值與條件

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 

如何改變「product_variation」以下post_type「產品」的值作爲父母的價值POST_TITLE。

,如果我有1000左右的產品,我能怎樣改變......?

+0

6,7,8是修正標識? –

+0

是的,它是固定的ID –

回答

0

你可以使用替換功能

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

請先嚐試在演示如果工作不是試圖在原有 –

+0

感謝您的查詢,但我能做到它adminer,因爲我有大約7000產品。我如何改變他們的散裝? –

+0

這是爲什麼呢,我有問你的id是修復? –