DataLane

9. Customer lifetime summary

mediumProNot started~15 minJoinsAggregation

Asked in screens shaped like: Airbnb, Booking, Expedia

Build the customer dimension the CRM team keeps asking for: order count, completed revenue, and first and last order timestamps. Customers with no orders must still appear, with zero revenue rather than NULL.

Requirements

  • Columns: customer_id, name, orders, completed_revenue, first_order_at, last_order_at
  • Every customer appears, even with no orders
  • orders counts order rows; completed_revenue only sums completed orders and is 0 when there are none
  • Order by completed_revenue descending, then customer_id

Expected output

customer_id, name, orders, completed_revenue, first_order_at, last_order_at

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Medium problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close