Easy JOINsAggregation Free

SQL interview question: Total Revenue per Customer

Customer Lifetime Value

The finance team needs to calculate total revenue generated by each customer.

Sum all order totals (total_amount) for each customer to find their lifetime value.

Return customer_id, customer_name, and lifetime_value. Only include customers who have placed at least one order.

Skills: SUM aggregation with GROUP BY and JOIN

Tables

orders 15 rows
  • order_id integer PK
  • customer_id integer → customers
  • order_date text
  • total_amount real
  • status text
order_idcustomer_idorder_datetotal_amountstatus
11012024-01-20249.99delivered
21012024-03-151999.99delivered
41012024-09-0579.99delivered
customers 12 rows
  • customer_id integer PK
  • name text
  • email text
  • city text
  • signup_date text
customer_idnameemailcitysignup_date
101Alice Mitchell[email protected]San Francisco2024-01-15
102Bob Chen[email protected]New York2024-02-20
103Carol Davis[email protected]Los Angeles2024-03-10

Keep going