Back to Practice
#0378

Users With All Required Events

MediumSQL24 min20 XP

Problem

Return user_id values that have all required events: view, click, and purchase.

Why This Matters

SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.

Schema

events(user_id INTEGER, event_name TEXT)

Examples

Example 1
Inputonly user 1 has all three required events
Outputuser 1

COUNT DISTINCT over the required set must equal the number of required events.

Constraints

  • Return only the requested columns.
  • Use deterministic ORDER BY when multiple rows are returned.
  • Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputonly user 1 has all three required events
Expected[[1]]

COUNT DISTINCT over the required set must equal the number of required events.

Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks