Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Function AVG
Functions SUM, MAX, MIN
28. SUM and COALESCE
Review

Instruction

Fine. Again, if we don't like to get NULL as a result, we can use COALESCE to replace it with any value of our choice:

SELECT COALESCE(SUM(price), 0)
FROM project;

If all prices happen to be NULLs, the above query will return 0 and not a NULL. Note that this time you can also write:

SELECT SUM(COALESCE(price, 0))
FROM project;

and the result will stay the same.

Exercise

Show translator ids with the sum of the prices of all the projects they have completed (as sum). Exclude project_id = 13 so that one of the translators has NULL prices only. Instead of that NULL sum, show 0.

Stuck? Here's a hint!

Group the rows by the translator id and use COALESCE.