CodeBlanks Logo Icon CodeBlanks

Calculated updates

Update based on the current value.

Calculated update

You can use a calculation in SET. You can use the old column value in the new value.

UPDATE products
SET price = price * 1.10
WHERE category = 'kitap';

This query raises prices of all books by 10%.

In products, price = price * 1.10 is updated. Only the rows where category = 'kitap' holds are affected.

Calculated update — details

SET price = price * 1.10 takes the old price, multiplies by 1.10 and writes it back. Ideal for bulk price changes.

Practice Calculated update

Raise all prices in products by 10%.

Starter code

query.sql
-- raise prices
UPDATE products
SET price = price

Sample solution

query.sql
UPDATE products
SET price = price * 1.10

Expected output

5 satır güncellendi

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does SET price = price * 1.10 do?

  • Sets the price to 10
  • Resets the price to 0
  • Increases the price by 10% Correct answer
  • Halves the price

Explanation: multiplies the old price by 1.10.

2 Raise price

Question
UPDATE products
SET price = price ____ 1.10
WHERE category = 'kitap';
Answer
UPDATE products
SET price = price * 1.10
WHERE category = 'kitap';

Explanation: price * 1.10 raises the price by 10%; the new value is computed from the old one.

3 Calculated updates: match the terms

Term Meaning
UPDATE update
SET new value
* multiply
WHERE condition

All lessons in Beginner