Order Totals for Every Customer
Updated
Problem statement
The customers table has one row per customer. The orders table has one row per order, and each order belongs to one customer through customer_id.
Write a report with one row for every customer, including customers who have never placed an order. For each customer, return:
customer_idandcustomer_nameorder_count: how many orders the customer placedtotal_amount: the sum of theamountof those orders
A customer with no orders has 0 in both order_count and total_amount. Sort the rows by customer_id from smallest to largest.
Interview follow-up
Be ready to explain your join choice. Why does this report need a LEFT JOIN, and when would an INNER JOIN be the better choice?
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
customers
One row per customer.
| Column | Type | Nullable | Description |
|---|---|---|---|
| customer_idPK | Integer | No | — |
| customer_name | Text | No | — |
orders
One row per order.
| Column | Type | Nullable | Description |
|---|---|---|---|
| order_idPK | Integer | No | — |
| customer_id | Integer | No | — |
| amount | Integer | No | — |
Foreign key: customer_id → customers(customer_id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| customer_id | Integer | No | — |
| customer_name | Text | No | — |
| order_count | Integer | No | — |
| total_amount | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- Each table has from
0to10^5rows. customer_idis unique incustomers, andorder_idis unique inorders.- Every
customer_idinordersalso appears incustomers. - No column is
NULL. 1 <= customer_id, order_id <= 10^9and1 <= amount <= 10^6.customer_namehas 1 to 50 characters. Two customers can have the same name.
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Delete Duplicate Employee RecordsInfosys · ONSITE INTERVIEWInfosys interview questions
- Records Created or Updated in a Time WindowPelatro · ONSITE INTERVIEW
- Top Ten Employee SalariesSolytics Partners · ONSITE INTERVIEW
- Latest New JobSphere · ONSITE INTERVIEW
- Employees Whose Manager Left the CompanyZS · ONSITE INTERVIEWZS interview questions
- Employees Above Average SalaryJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Retrieve Every Student RecordLSEG · ONSITE INTERVIEWLSEG interview questions
- Conditionally Insert or Update RecordsKlaviyo · ONSITE INTERVIEWKlaviyo interview questions
- Employees with Matching DepartmentsAMD · ONSITE INTERVIEWAMD interview questions
- New-User Devices That Opened an AppMicrosoft · ONSITE INTERVIEWMicrosoft interview questions