Back to Practice
#0389

Simple Customer Lifetime Value

EasySQL15 min10 XP

Problem

Return customer_id and lifetime_value ordered by lifetime_value descending, then customer_id.

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

purchases(customer_id INTEGER, amount INTEGER)

Examples

Example 1
Inputcustomer 2 has highest total
Output2 first, then 1, then 3

Lifetime value is total purchase amount per customer.

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
Inputcustomer 2 has highest total
Expected[[2,200],[1,120],[3,20]]

Lifetime value is total purchase amount per customer.

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