Write SQL and Python, run instantly in your browser, and track your progress.
You are a Data Analyst at Amazon. The Analytics team wants to understand purchase patterns by calculating each order's percentage contribution to its customer's total spending. Merge orders with customers and calculate each order's share of the customer's total.
| Column Name | Type |
|---|---|
| order_id | int64 |
| order_number | object |
| customer_id | int64 |
| order_datetime |
You are a Data Analyst at Amazon. The Analytics team wants to understand purchase patterns by calculating each order's percentage contribution to its customer's total spending. Merge orders with customers and calculate each order's share of the customer's total.
| Column Name | Type |
|---|---|
| order_id | int64 |
| order_number | object |
| customer_id | int64 |
| order_datetime |
| object |
| object |
| status | object |
| status | object |
| total_amount | float64 |
| total_amount | float64 |
| payment_status | object |
| payment_status | object |
| Column Name | Type |
|---|---|
| customer_id | int64 |
| full_name | object |
| object | |
| city | object |
| state | object |
| country | object |
| Column Name | Type |
|---|---|
| customer_id | int64 |
| full_name | object |
| object | |
| city | object |
| state | object |
| country | object |
| order_id | order_number | customer_id | order_datetime | status | total_amount | payment_status |
|---|---|---|---|---|---|---|
| 1 | ORD-001 | 1 | 2025-01-15 | delivered | 200.00 | captured |
| 2 |
| order_id | order_number | customer_id | order_datetime | status | total_amount | payment_status |
|---|---|---|---|---|---|---|
| 1 | ORD-001 | 1 | 2025-01-15 | delivered | 200.00 | captured |
| 2 |
| customer_id | full_name | city | state | country | created_at | |
|---|---|---|---|---|---|---|
| 1 | Alice Johnson | alice@email.com | Seattle | WA | US | 2024-06-01 |
| 2 |
| customer_id | full_name | city | state | country | created_at | |
|---|---|---|---|---|---|---|
| 1 | Alice Johnson | alice@email.com | Seattle | WA | US | 2024-06-01 |
| 2 |
| order_id | full_name | total_amount | customer_total | order_pct |
|---|---|---|---|---|
| 1 | Albert Nakamura | 55.32 | 3076.26 | 1.80 |
| 2 | Vikram Zhang | 662.48 | 1207.10 | 54.88 |
| 3 | Helen Perry | 88.66 | 88.66 | 100 |
| order_id | full_name | total_amount | customer_total | order_pct |
|---|---|---|---|---|
| 1 | Albert Nakamura | 55.32 | 3076.26 | 1.80 |
| 2 | Vikram Zhang | 662.48 | 1207.10 | 54.88 |
| 3 | Helen Perry | 88.66 | 88.66 | 100 |
Showing first 5 of 75 rows.
Showing first 5 of 75 rows.
1. DataFrames:
2. Merge:
3. Calculations:
4. Output:
1. DataFrames:
2. Merge:
3. Calculations:
4. Output:
| created_at | object |
| created_at | object |
| ORD-002 |
| ORD-002 |
| 1 |
| 1 |
| 2025-01-20 |
| 2025-01-20 |
| delivered |
| delivered |
| 300.00 |
| 300.00 |
| captured |
| captured |
| 3 | ORD-003 | 2 | 2025-01-18 | delivered | 150.00 | captured |
| 3 | ORD-003 | 2 | 2025-01-18 | delivered | 150.00 | captured |
| 4 | ORD-004 | 1 | 2025-01-25 | shipped | 500.00 | captured |
| 4 | ORD-004 | 1 | 2025-01-25 | shipped | 500.00 | captured |
| 5 | ORD-005 | 2 | 2025-01-22 | delivered | 350.00 | captured |
| 5 | ORD-005 | 2 | 2025-01-22 | delivered | 350.00 | captured |
| Bob Smith |
| Bob Smith |
| bob@email.com |
| bob@email.com |
| Austin |
| Austin |
| TX |
| TX |
| US |
| US |
| 2024-07-15 |
| 2024-07-15 |
| 4 | Patrick Turner | 322.87 | 3611.42 | 8.94 |
| 4 | Patrick Turner | 322.87 | 3611.42 | 8.94 |
| 5 | Patrick Turner | 629.34 | 3611.42 | 17.43 |
| 5 | Patrick Turner | 629.34 | 3611.42 | 17.43 |