Reputation: 639
I have a products table where I store the original price and a discount percentage:
mysql> select * from products;
+---------------+--------+-----------+--------+
| concept | price | discount | currency |
+---------------+--------+-----------+--------+
| yyy | 1 | 0.00 | usd |
| xxx | 10 | 50.00 | usd |
+---------------+--------+-----------+--------+
How could I calculate the total price of each item in a SELECT stament using the price and discount column so I can get the following
mysql> select ???????
+---------------+--------+--------+
| concepto | total | currency |
+---------------+--------+--------+
| yyy | 1 | usd |
| xxx | 5 | usd |
+---------------+--------+--------+
Upvotes: 0
Views: 2270
Reputation: 222412
That's simple arithmetics:
select
concept,
price * (1 - discount / 100) total,
currency
from products
Upvotes: 2