How would you design a customer schema table and answer the follow-up SQL questions?
Use the supplied customer, order, and order-item tables. Return a customer-level summary based only on completed orders, while retaining customers who have no completed orders.
customer_id, full_name, completed_order_count, completed_spend, latest_completed_order_date, and customer_segment.NULL latest date when applicable.completed_spend descending, then customer_id ascending.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| full_name | VARCHAR(120) | Customer's full name |
| VARCHAR(255) | Customer email address | |
| country_code | VARCHAR(2) | Two-letter customer country code |
| customer_status | VARCHAR(20) | Current customer status |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer who placed the order |
| order_status | VARCHAR(20) | Order lifecycle status |
| order_date | DATE | Date the order was placed |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order-line identifier |
| order_id | INT | Order containing the item |
| product_name | VARCHAR(120) | Name of the ordered item |
| quantity | INT | Number of units ordered |
| unit_price | NUMERIC(10,2) | Price per unit |