Back to Practice
#0362

Users Above Global Average Orders

MediumSQL24 min20 XP

Problem

Return user_id and order_count for users whose order count is above the average order count across users with orders.

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

orders(order_id INTEGER, user_id INTEGER)

Examples

Example 1
Inputcounts are 3, 1, 1
Outputuser 1 only

The average count is 1.67, so only 3 is above average.

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
Inputcounts are 3, 1, 1
Expected[[1,3]]

The average count is 1.67, so only 3 is above average.

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