Beginner
Open
Pro
Users Who Never Purchased Returns Zero Rows
A colleague wants the list of users who never appear in a refunds
table (refunds(refund_id, user_id NULLABLE, amount); some historic
refunds were recorded without a user):
SELECT user_id FROM users
WHERE user_id NOT IN (SELECT user_id FROM refunds);
It returns zero rows, even though most users have never had a refund.
- Explain, step by step using three-valued logic, why the result is empty.
- Give two correct rewrites and state which you would recommend.
- The same colleague computes
AVG(amount)overrefundsand is surprised it differs fromSUM(amount) / COUNT(*). Why?
Share this question