Paths Subjects Questions Quizzes Pricing Search
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.

  1. Explain, step by step using three-valued logic, why the result is empty.
  2. Give two correct rewrites and state which you would recommend.
  3. The same colleague computes AVG(amount) over refunds and is surprised it differs from SUM(amount) / COUNT(*). Why?

Share this question

← Back to SQL for Data Analysis practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.