Learn SQL: Arithmetic
Arithmetic in SELECT
It is stocktaking day. Mo wants to know what the stock is worth, and Rosa is hatching a discount campaign. Time to do some sums.
Arithmetic in SELECT
In a SELECT you can also do sums, with +, -, * (times) and / (divided by).
The calculation happens for each row separately. Here you see the price of a double portion for each product.
SELECT name, price, price * 2 AS doubled FROM products LIMIT 4| name | price | doubled |
|---|---|---|
| House Blend | 12.5 | 25 |
| Ethiopia Yirgacheffe | 16.9 | 33.8 |
| Colombia Huila | 14.75 | 29.5 |
| Espresso Forte | 11.95 | 23.9 |
Try it yourself
Mo wants the name and the stock value (price times stock) of each product. Call that column value.
Ready for more?
The full lesson has 6 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson