2017-05-22 4 views
0

Ok, um es ganz klar zu machen, ich habe Tabelle wie folgt aussehen:SQL - Ersetzen Wert der Spalte aus einer anderen Spalte Wert mit der Bedingung

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 

Ich möchte wie dieser sein:

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 

Wie ändert man den Wert post_title von "product_variation" nach dem Wert von post_type "product" als übergeordnetes Element.

und wenn ich über 1000 Produkt habe, wie kann ich es ändern ...?

+0

6,7,8 sind fix id ersetzen? –

+0

ja es ist feste ID –

Antwort

0

Sie verwenden können, Funktion

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

Bitte versuchen Sie es zuerst in der Demo, wenn die Arbeit als in Original –

+0

versuchen, danke für die Abfrage, aber ich es geschafft, es auf Administrator zu tun, wie ich über 7000 Produkt habe. Wie ändere ich sie in der Masse? –

+0

dies warum ich frage dich ID ist fix? –

Verwandte Themen