Best April deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting data
Modifying data
11. Modify data – arithmetic operations
Deleting data
CRUD

Instruction

Nice! So far we've only used fixed values when updating rows. We can, however, make the database do some math too. Take a look:

UPDATE user 
SET
  age = 10 + age 
WHERE id = 5;

As a result of this query, the user with the ID 5 will be older by 10 years compared to their current age – for whatever reason.

Let's practice modifying data once again, this time using some arithmetic!

Exercise

The restaurant owners think the starters are so delicious and popular that they should be much more expensive. Try multiplying their prices by 2.

Think in advance: what will the price of Kosovo Bread be after the change? Remember to check if your guess was correct!

Stuck? Here's a hint!

Type:

UPDATE dish 
SET
  price = 2 * price 
WHERE type = 'starter';