Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
See the whole table
Select some columns
Filtering rows
Logic
Text patterns
To be or NULL to be
A little bit of mathematics
21. Basic mathematical operators
Let's practice

Instruction

Nice! We may now move on to our next problem: simple mathematics. Can you add or multiply numbers in SQL? Yes, you can! Take a look at the example:

SELECT *
FROM user
WHERE (monthly_salary * 12) > 50000;

In the above example, we multiply the monthly salary by 12 to get the annual salary by using the asterisk (*). We may then do whatever we want with the new value – in this case, we compare it with $50,000.

In this way, you can add (+), subtract (-), multiply (*) and divide (/) numbers.

Exercise

Select all columns for cars with a tax amount over $2000. The tax amount for all cars is 20% of their price. Multiply the price by 0.2 to get the tax amount.

Stuck? Here's a hint!

Type:

SELECT *
FROM car
WHERE (price * 0.2) > 2000;