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
Result
namepricedoubled
House Blend12.525
Ethiopia Yirgacheffe16.933.8
Colombia Huila14.7529.5
Espresso Forte11.9523.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