Customer Order Count Distribution by Country
Updated
Problem statement
For every country, count its customers in three mutually exclusive order-frequency categories:
zero_order_customers: customers who have never placed an order.one_order_customers: customers who have placed exactly one order.multiple_order_customers: customers who have placed at least two orders.
Include every country, even when it has no customers. Customers with no matching row in orders must remain in the result.
Result
Return country_id, country_name, zero_order_customers, one_order_customers, and multiple_order_customers. Order rows by country_name ascending.
Table schema
MySQLPostgreSQLPandas
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.
countries
| Column | Type | Nullable | Description |
|---|---|---|---|
| country_idPK | Integer | No | — |
| country_name | Text | No | — |
customers
| Column | Type | Nullable | Description |
|---|---|---|---|
| customer_idPK | Integer | No | — |
| country_id | Integer | No | — |
Foreign key: country_id → countries(country_id)
orders
| Column | Type | Nullable | Description |
|---|---|---|---|
| order_idPK | Integer | No | — |
| customer_id | Integer | No | — |
| country_id | Integer | No | — |
| order_date | Date | No | — |
Foreign key: customer_id → customers(customer_id)
Foreign key: country_id → countries(country_id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| country_id | Integer | No | — |
| country_name | Text | No | — |
| zero_order_customers | Integer | No | — |
| one_order_customers | Integer | No | — |
| multiple_order_customers | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- Each customer belongs to exactly one country.
- Every order belongs to exactly one customer, and its
country_idmatches that customer's country. - Every
country_nameis unique. - A customer's category is based on the number of distinct order rows for that customer.
- Each input table contains at most
2,000rows.
More Apple Phone Screen questions
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
- Maintain a Consistent-Hashing RingPHONE SCREEN · Seen Oct 2026
- Count Nodes in a ChainPHONE SCREEN · Seen Oct 2026
- Run-Length DecodingPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Second Highest SalaryPaytm · PHONE SCREENPaytm interview questions
- Employees Who Earn More Than Their ManagersNykaa · PHONE SCREENNykaa interview questions
- Employees Who Joined More Than a Week AgoNewgen Software · PHONE SCREEN
- Departments Without EmployeesDell Technologies · PHONE SCREENDell Technologies interview questions
- Second-Highest Distinct SalaryChubb · PHONE SCREENChubb interview questions
- Swap Two Gender ValuesInfosys · PHONE SCREENInfosys interview questions
- Find Rows Common to Two TablesSalesforce · PHONE SCREENSalesforce interview questions
- Count Records Present in A but Not BCapital One · PHONE SCREENCapital One interview questions
- Employees Earning More Than Their ManagerMygate · PHONE SCREENMygate interview questions
- Classify Tree Nodes with SQLOracle · PHONE SCREENOracle interview questions
Apple interview experiences
- Apple SWE Phone Screen: Subarray Products: 1 Experience
- Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
- Apple AI Coding and Related Interviews: 17 Experiences
- Apple India SWE New Grad Interviews: 5 Experiences
- Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
- Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)