Skip to main content
← Back to Code Arena
Medium Apprentice SpeedRun aggregates null count

SQL: COUNT, COUNT(*), and NULLs

+180 XP · 5 min · attempt 1

Problem

Table orders(id, customer_id) has these rows:

    1, 100
    2, 100
    3, 200
    4, NULL
    5, NULL
    6, 200

Compute each value and ADD them together:

    A = SELECT COUNT(*)              FROM orders;
    B = SELECT COUNT(customer_id)    FROM orders;
    C = SELECT COUNT(DISTINCT customer_id) FROM orders;

Enter a single integer for A + B + C.

Starter

-- COUNT(*) counts rows.
-- COUNT(col) counts non-NULL values.
-- COUNT(DISTINCT col) counts distinct non-NULL values.

Your answer

Playing as a guest — you'll be asked for a display name on submit. Log in to keep your XP across devices.