LTV Prediction

ASKED IN INTERVIEW
10pts
Netflix

Problem Statement

Calculate the total Lifetime Value (LTV) for every user. LTV is the sum of all successful payments made by the user.

Rules:

  • Output columns: user_id, total_ltv.
  • Filter: status = Success.
  • Handling empty data: Return 0 for users with no successful payments.
  • Sort by total_ltv DESC.
Tests your understanding of
Aggregation, Joins, COALESCE and Summation

Input Tables

users
user_id(INTEGER)user_name(VARCHAR)created_at(TIMESTAMP)
1Alice2023-01-01 10:00:00
2Bob2023-05-10 12:00:00
3Charlie2024-01-01 08:00:00
payments
payment_id(INTEGER)user_id(INTEGER)amount(DECIMAL)status(VARCHAR)payment_date(TIMESTAMP)
501115.99Success2023-02-01 00:00:00
502115.99Success2023-03-01 00:00:00
503219.99Success2023-06-01 00:00:00
504219.99Failed2023-07-01 00:00:00
subscriptions
user_id(INTEGER)plan_type(VARCHAR)
1Standard

Expected Output

user_id(INTEGER)total_ltv(DECIMAL)
131.98
219.99
30

Tags

HardASKED IN INTERVIEWAggregationJoinsCOALESCESummation
15-25 min
48%

Hints