hostbox
11-01-2007, 03:00 AM
Hi!
I got a table in a database called "_price"
On this table there is a value "amount" that is 100.00
Would it be possible to run an SQL query using phpmyadmin to:
- Add 2.5% surcharge?
Hence, 232 values will change depending on amount, for our example 100.00 it would change to 102.50
Thanks!
mwaseem
11-01-2007, 06:17 AM
Nop. It can't be done using an SQL query, but you have a write a script which would
1. Read existing amount
2. Update amount by adding percentage value
3. Update the field with new data
thePhil
11-01-2007, 06:46 AM
Nop. It can't be done using an SQL query, but you have a write a script which would
It most certainly can:
mysql> CREATE TABLE t1 (field DECIMAL(10,2), id INTEGER PRIMARY KEY);
Query OK, 0 rows affected (0.03 sec)
mysql> INSERT INTO t1 (field, id) VALUES (100.0, 1);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO t1 (field, id) VALUES (1000.0, 2);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO t1 (field, id) VALUES (500.0, 3);
Query OK, 1 row affected (0.00 sec)
mysql> UPDATE t1 SET field=field+ (field * 0.025);
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select * from t1;
+---------+----+
| field | id |
+---------+----+
| 102.50 | 1 |
| 1025.00 | 2 |
| 512.50 | 3 |
+---------+----+
3 rows in set (0.00 sec)
Phil.