0

I've a table called WP_POSTMETA with a column META_KEY and a column META_VALUE.

I'd like to multiply the META_VALUE '_PRICE' with a factor 1.5

Who can help me with the right MYSQL query? I have to multiply prices for about 8000+ items and want to update them all in one action...

Please see also

enter image description here

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
EWM
  • 11

3 Answers3

2

You can try like this:-

Update WP_POSTMETA
SET META_VALUE = Meta_Value*1.5
WHERE META_KEY = '_PRICE' 
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
1

Assuming I understand correctly...

You want to update the Meta_value * 1.5 where the meta_key = '_PRICE'

Update WP_POSTMETA
SET META_VALUE = Meta_Value*1.5
WHERE META_KEY = '_PRICE'

To view the results before you run the above update. update..

Select MEta_value*1.5 as newVal, Meta_value, Meta_key
from  WP_POSTMETA
WHERE META_KEY = '_PRICE'
xQbert
  • 34,733
  • 2
  • 41
  • 62
0

Or like this with a transaction:

BEGIN;

Update WP_POSTMETA
SET META_VALUE = Meta_Value*1.5
WHERE META_KEY = '_PRICE'



Select MEta_value*1.5 as newVal, Meta_value, Meta_key
from  WP_POSTMETA
WHERE META_KEY = '_PRICE'

If you're happy with the result

COMMIT; 

Else do a rollback

ROLLBACK; 

Actually you should do all statements that modifies production data in a transaction.

marko
  • 10,684
  • 17
  • 71
  • 92