Find orders with totals above 1000 and their customer names
Company: Coinbase
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Find all orders with `total_amount` strictly greater than 1000. Return `order_id`, `customer_name`, `order_date`, `total_amount`, ordered by `total_amount` descending, then `order_id` ascending.
```hint The boundary
Check what your filter does with an order of exactly 1000.00.
```
### Input Table(s)
Table `customers` (primary key `customer_id`):
| Column | Type | Meaning |
|---|---|---|
| customer_id | INT | Unique customer identifier |
| customer_name | VARCHAR(100), NOT NULL | Customer's name |
Table `orders` (primary key `order_id`; `customer_id` is a foreign key to `customers.customer_id`):
| Column | Type | Meaning |
|---|---|---|
| order_id | INT | Unique order identifier |
| customer_id | INT, NOT NULL | Customer who placed the order |
| order_date | DATE, NOT NULL | Date of the order |
| total_amount | DECIMAL(10,2), NOT NULL | Order total |
### Output Contract
- Columns, in this order: `order_id`, `customer_name`, `order_date`, `total_amount`.
- One row per order whose `total_amount` is strictly greater than 1000.
- `order_date` and `total_amount` are returned as stored, with no rounding or reformatting.
- Sort by `total_amount` descending, then `order_id` ascending. `order_id` is unique, so the order is fully determined.
### Example
`customers`
| customer_id | customer_name |
|---|---|
| 1 | Alice Chen |
| 2 | Bob Smith |
| 3 | Carla Diaz |
`orders`
| order_id | customer_id | order_date | total_amount |
|---|---|---|---|
| 1001 | 1 | 2024-05-01 | 1500.00 |
| 1002 | 2 | 2024-05-02 | 1000.00 |
| 1003 | 3 | 2024-05-03 | 2500.50 |
| 1004 | 1 | 2024-05-04 | 1500.00 |
| 1005 | 2 | 2024-05-05 | 1000.01 |
| 1006 | 3 | 2024-05-06 | 250.00 |
Expected output:
| order_id | customer_name | order_date | total_amount |
|---|---|---|---|
| 1003 | Carla Diaz | 2024-05-03 | 2500.50 |
| 1001 | Alice Chen | 2024-05-01 | 1500.00 |
| 1004 | Alice Chen | 2024-05-04 | 1500.00 |
| 1005 | Bob Smith | 2024-05-05 | 1000.01 |
Order 1002 is exactly 1000.00, which is not strictly greater than 1000, so it is left out, and order 1006 is far below the threshold. Orders 1001 and 1004 tie at 1500.00 and are listed by `order_id`. Alice Chen appears twice because each qualifying order is its own row.
### Constraints and Clarifications
- Each table has at most 10,000 rows, and `order_id` is unique.
- `total_amount` is non-negative with up to 2 decimal places.
- Every `orders.customer_id` references a valid `customers.customer_id`, so every order has a customer name.
- All columns are NOT NULL, so no NULL handling is needed.
- The threshold applies to each order's own `total_amount`. A customer's combined spending does not matter, and a customer with several large orders appears once per order.
- Orders with the same `total_amount` are ordered by `order_id` ascending.
Overview: Write a SQL query that lists every order above a fixed amount together with the customer's name, sorted by amount with an order id tie-break. It tests inner joins, strict comparison filters and deterministic ordering, a common pattern in entry-level SQL screens.