Practice · Business · Medium
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.
businessmen(name, net_worth_usd_bn). Use COALESCE(net_worth_usd_bn, 0) to substitute 0 for NULL.
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.
COALESCE returns the first non-NULL of its arguments — the clean way to supply a default for missing data. (SQLite docs)