Revision
Comparisons with NULL
Functions with NULL
COALESCE to the rescue
18. COALESCE with calculations
NULLIF
Revision and practice

Instruction

Good. You can also use COALESCE in calculations in a similar way:

COALESCE(price, 0) * 1.05

The above query will return the price times 1.05 or 0 (0 * 1.05 = 0) if the price is NULL.

Exercise

The company organized a discount campaign on all prices: -10%.

Show the names of all products together with their price and the new prices (name the column new_price). If there is no price, show 0.0 in the column new_price.

Stuck? Here's a hint!

You can write COALESCE(price*0.9,0.0) to get the right price.

Console

Code editor

Result

TableConsole