Practice · Business · Medium

Fill the blanks (COALESCE)

Return every businessman and their net worth, but show 0 where the net worth is NULL. Columns: name and worth, richest first.

Runs in your browser. No signup needed.

What you are given

businessmen(name, net_worth_usd_bn). Use COALESCE(net_worth_usd_bn, 0) to substitute 0 for NULL.

Starting point

SELECT name, COALESCE(net_worth_usd_bn, 0) AS worth
FROM businessmen
ORDER BY worth DESC;

The reference solution is checked automatically when you run your query on the practice page — results are compared row by row, and order matters for this one.

Did you know

COALESCE returns the first non-NULL of its arguments — the clean way to supply a default for missing data. (SQLite docs)

More Business challenges

Open it in the playground →