Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Add 15% to a price column in db
08-28-2013, 09:07 PM #1
- Join Date
- Nov 2011
- Thanked 0 Times in 0 Posts
Add 15% to a price column in db
I have a db with products and I need to add 15% (column 'price') to some products from db, depending on category (column 'category').
How can I do that instead of adding manual to each row?
I use PhpMyAdmin if does any matter.
Thank you in advance.
08-28-2013, 11:33 PM #2
Unless this is a *PERMANENT* price change, DO NOT DO IT!
If this is, for example, for the purpose of having a temporary surcharge on certain category(ies), do it in the SQL query, instead:
SELECT productid, productname, price, IF(category IN ('bedding','furniture'), '15%', 'None') AS surcharage, price * IF(category IN ('bedding','furniture'), 1.15, 1.0) AS priceWithSurcharge FROM products
UPDATE products SET price = price * 1.15 WHERE category IN ('bedding','furniture')
Last edited by Old Pedant; 08-28-2013 at 11:35 PM.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.