Reviews Per Reviewer

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L3
Asked in
General Assembly

Problem

The engineering manager is balancing review workloads and needs to see how many code reviews each reviewer is currently carrying.

The workload split across reviewers.

Tables

code_reviews

Columns: review_id INTEGER, repo_name TEXT, author TEXT, reviewer TEXT, status TEXT, comments INTEGER, opened_at TEXT, merged TEXT

code_reviews: 10 of 200 rows
review_idrepo_nameauthorreviewerstatuscommentsopened_atmerged
1053backend-apibobevechanges_requested32026-02-022026-02-05
1106infracharliefrankpending62026-03-032026-03-06
1159ml-pipelinedanagraceApproved92026-04-042026-04-07
1212mobile-appevehankPENDING122026-05-05NULL
1265data-platformfrankalicemerged152026-06-062026-06-09
1318frontendgracebobapproved182026-07-072026-07-10
1371backend-apihankcharliechanges_requested212026-08-082026-08-11
1424infraaliceNULLpending242026-09-09NULL
1477ml-pipelinebobeveApproved272026-01-102026-01-13
1530mobile-appcharliefrankPENDING302026-02-112026-02-14

Expected output

First 5 of 8 rows
reviewerreview_count
NULL24
alice24
bob24
eve26
frank26

Worked solution and explanation

This is a per-person tally of one table, and the easy part really is easy: one row per reviewer, one number each. What separates candidates is the 24 reviews nobody has picked up. They sit under a NULL reviewer, and two reflexes erase them: counting the column instead of the rows, or 'cleaning' the missing reviewer out. Either one hides from the manager exactly the pile they most needed to see.

Reading the request

Step 1: Decide what one output row is

One row per reviewer, and the unassigned reviews get a slot too. The preview's blank first line with 24 beside it is the tell: the answer keeps them as their own bucket instead of dropping them.

Step 2: Count reviews, not reviewer values

COUNT(*) counts the rows in each group. COUNT(reviewer) counts non-null reviewer values, so in the group whose key is NULL it returns 0, even though 24 reviews live there.

Step 3: Leave status and merged alone

'Currently carrying' sounds like a hint to filter on status or merged. Check it against the preview: the unfiltered tally matches it line for line, and any filter on review state pushes every number below it.

One row per `reviewer`, unassigned included
SELECT reviewer, COUNT(*) AS review_count
FROM code_reviews
GROUP BY reviewer
Counts the column
COUNT(reviewer) skips nulls, so the unassigned group still appears but reads 0. The other seven reviewers look right, which is why this slips through review.
Counts the rows
COUNT(*) counts every review in the group, so the unassigned bucket reports its true 24 next to eve's 26 and alice's 24.

Common follow-up questions