akko
akko

Reputation: 639

How to calculate the price of a product using a discount in mysql?

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

Answers (1)

GMB
GMB

Reputation: 222412

That's simple arithmetics:

select 
    concept,
    price * (1 - discount / 100) total,
    currency
from products

Upvotes: 2

Related Questions