SQLSQL
#11

Calculate Customer Lifetime Value with INNER JOIN in SQL

EasyAmazon
Interview Question #11
Asked at Amazon

Given `customers` (customer_id, name) and `orders` (order_id, customer_id, total_amount), write a SQL query to return each customer's `name`, total number of orders `order_count`, and total spend `total_spent`. Exclude customers who haven't placed orders.

Input Table: customers & orders
4 rows preview
customer_idnameorder_idtotal_amount
1Aarav1011500
1Aarav1022500
2Bhavna1033000
3ChiragNULLNULL
Expected Output Structure2 rows
nameorder_counttotal_spent
Aarav24000
Bhavna13000
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us