Write SQL and Python, run instantly in your browser, and track your progress.
You are a Financial Analyst at Amazon. The finance team is preparing the quarterly revenue reconciliation report and needs a normalized view of all delivered orders from the last 90 days, paired with their most recent successful payment capture.
Your task is to combine data from the orders, shipments, and payments tables to create a clean dataset. For orders with multiple payment captures, only the most recent one should be included.
| Column Name | Type |
|---|---|
| order_id | INTEGER |
You are a Financial Analyst at Amazon. The finance team is preparing the quarterly revenue reconciliation report and needs a normalized view of all delivered orders from the last 90 days, paired with their most recent successful payment capture.
Your task is to combine data from the orders, shipments, and payments tables to create a clean dataset. For orders with multiple payment captures, only the most recent one should be included.
| Column Name | Type |
|---|---|
| order_id | INTEGER |
| order_number |
| order_number |
| TEXT |
| TEXT |
| customer_id | INTEGER |
| customer_id | INTEGER |
| order_datetime | TEXT |
| order_datetime | TEXT |
| status | TEXT |
| status | TEXT |
| fulfillment_type | TEXT |
| fulfillment_type | TEXT |
| ship_city | TEXT |
| ship_city | TEXT |
| ship_state | TEXT |
| ship_state | TEXT |
| ship_country | TEXT |
| ship_country | TEXT |
| shipping_service_level | TEXT |
| shipping_service_level | TEXT |
| subtotal | REAL |
| subtotal | REAL |
| shipping_fee | REAL |
| shipping_fee | REAL |
| tax | REAL |
| tax | REAL |
| discount | REAL |
| discount | REAL |
| total_amount | REAL |
| total_amount | REAL |
| payment_status | TEXT |
| payment_status | TEXT |
| created_at | TEXT |
| created_at | TEXT |
| order_id | order_number | customer_id | order_datetime | status | fulfillment_type | ship_city | ship_state | ship_country | shipping_service_level | subtotal | shipping_fee | tax | discount | total_amount |
|---|
| order_id | order_number | customer_id | order_datetime | status | fulfillment_type | ship_city | ship_state | ship_country | shipping_service_level | subtotal | shipping_fee | tax | discount | total_amount |
|---|
| Column Name | Type |
|---|---|
| shipment_id | INTEGER |
| order_id | INTEGER |
| warehouse_code | TEXT |
| carrier_name | TEXT |
| service_level | TEXT |
| tracking_number | TEXT |
| Column Name | Type |
|---|---|
| shipment_id | INTEGER |
| order_id | INTEGER |
| warehouse_code | TEXT |
| carrier_name | TEXT |
| service_level | TEXT |
| tracking_number | TEXT |
| shipment_id | order_id | warehouse_code | carrier_name | service_level | tracking_number | ship_date | est_delivery_date | delivery_date | status | weight_kg | shipping_fee_charged |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 |
| shipment_id | order_id | warehouse_code | carrier_name | service_level | tracking_number | ship_date | est_delivery_date | delivery_date | status | weight_kg | shipping_fee_charged |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 |
| Column Name | Type |
|---|---|
| payment_id | INTEGER |
| order_id | INTEGER |
| method | TEXT |
| processor | TEXT |
| amount | REAL |
| currency | TEXT |
| Column Name | Type |
|---|---|
| payment_id | INTEGER |
| order_id | INTEGER |
| method | TEXT |
| processor | TEXT |
| amount | REAL |
| currency | TEXT |
| payment_id | order_id | method | processor | amount | currency | status | transaction_id | auth_time | capture_time | refund_time |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | apple_pay | stripe |
| payment_id | order_id | method | processor | amount | currency | status | transaction_id | auth_time | capture_time | refund_time |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | apple_pay | stripe |
| order_id | order_number | payment_id | capture_date | delivery_date | order_status_upper | currency_upper |
|---|---|---|---|---|---|---|
| 15 | ORD-10015 | 15 | 2025-08-23 | 2025-08-25 | DELIVERED | USD |
| 11 | ORD-10011 | 11 | 2025-06-29 | 2025-06-28 | DELIVERED |
| order_id | order_number | payment_id | capture_date | delivery_date | order_status_upper | currency_upper |
|---|---|---|---|---|---|---|
| 15 | ORD-10015 | 15 | 2025-08-23 | 2025-08-25 | DELIVERED | USD |
| 11 | ORD-10011 | 11 | 2025-06-29 | 2025-06-28 | DELIVERED |
2 rows returned. Delivered orders with their latest captured payment from last 90 days.
2 rows returned. Delivered orders with their latest captured payment from last 90 days.
1. Output Columns:
order_id: The order's unique identifierorder_number: The order numberpayment_id: The payment's unique identifiercapture_date: The date the payment was captured, formatted as YYYY-MM-DDdelivery_date: The date the shipment was delivered, formatted as YYYY-MM-DDorder_status_upper: The order status, converted to all uppercasecurrency_upper: The payment currency, converted to all uppercase1. Output Columns:
order_id: The order's unique identifierorder_number: The order numberpayment_id: The payment's unique identifiercapture_date: The date the payment was captured, formatted as YYYY-MM-DDdelivery_date: The date the shipment was delivered, formatted as YYYY-MM-DDorder_status_upper: The order status, converted to all uppercasecurrency_upper: The payment currency, converted to all uppercase| payment_status |
|---|
| payment_status |
|---|
| created_at |
|---|
| created_at |
|---|
| 1 | ORD-10001 | 46 | 2025-08-20 07:01:34 | shipped | pickup | pickup | 50.96 | 0.0 | 4.36 | 0.0 | 55.32 | captured | 2025-08-20 07:01:34 | |||
| 2 | ORD-10002 | 19 | 2025-02-24 04:56:03 | delivered | ship |
| 1 | ORD-10001 | 46 | 2025-08-20 07:01:34 | shipped | pickup | pickup | 50.96 | 0.0 | 4.36 | 0.0 | 55.32 | captured | 2025-08-20 07:01:34 | |||
| 2 | ORD-10002 | 19 | 2025-02-24 04:56:03 | delivered | ship |
| ship_date | TEXT |
| ship_date | TEXT |
| est_delivery_date | TEXT |
| est_delivery_date | TEXT |
| delivery_date | TEXT |
| delivery_date | TEXT |
| status | TEXT |
| status | TEXT |
| weight_kg | REAL |
| weight_kg | REAL |
| shipping_fee_charged | REAL |
| shipping_fee_charged | REAL |
| W3-Atlanta |
| W3-Atlanta |
| UPS |
| UPS |
| economy |
| economy |
| TRK100002 |
| TRK100002 |
| 2025-02-25 |
| 2025-02-25 |
| 2025-03-04 |
| 2025-03-04 |
| 2025-03-05 |
| 2025-03-05 |
| delivered |
| delivered |
| 3.04 |
| 3.04 |
| 5.99 |
| 5.99 |
| 2 | 3 | W4-Dallas | USPS | expedited | TRK100003 | 2025-02-15 | 2025-02-18 | in_transit | 9.2 | 14.99 |
| 2 | 3 | W4-Dallas | USPS | expedited | TRK100003 | 2025-02-15 | 2025-02-18 | in_transit | 9.2 | 14.99 |
| 3 | 4 | W2-Chicago | USPS | standard | TRK100004 | 2025-02-07 | 2025-02-12 | picked_up | 7.17 | 5.0 |
| 3 | 4 | W2-Chicago | USPS | standard | TRK100004 | 2025-02-07 | 2025-02-12 | picked_up | 7.17 | 5.0 |
| 4 | 5 | W3-Atlanta | UPS | standard | TRK100005 | 2025-06-26 | 2025-07-01 | return_to_sender | 6.35 | 5.0 |
| 4 | 5 | W3-Atlanta | UPS | standard | TRK100005 | 2025-06-26 | 2025-07-01 | return_to_sender | 6.35 | 5.0 |
| 5 | 6 | W3-Atlanta | UPS | standard | TRK100006 | 2025-04-08 | 2025-04-13 | 2025-04-12 | delivered | 4.66 | 9.99 |
| 5 | 6 | W3-Atlanta | UPS | standard | TRK100006 | 2025-04-08 | 2025-04-13 | 2025-04-12 | delivered | 4.66 | 9.99 |
| status | TEXT |
| status | TEXT |
| transaction_id | TEXT |
| transaction_id | TEXT |
| auth_time | TEXT |
| auth_time | TEXT |
| capture_time | TEXT |
| capture_time | TEXT |
| refund_time | TEXT |
| refund_time | TEXT |
| 55.32 |
| 55.32 |
| USD |
| USD |
| captured |
| captured |
| TX200002 |
| TX200002 |
| 2025-08-20 07:01:34 |
| 2025-08-20 07:01:34 |
| 2025-08-20 15:01:34 |
| 2025-08-20 15:01:34 |
| 2 | 2 | google_pay | square | 662.48 | USD | partial_refund | TX200003 | 2025-02-24 04:56:03 | 2025-02-26 06:56:03 | 2025-03-04 06:56:03 |
| 2 | 2 | google_pay | square | 662.48 | USD | partial_refund | TX200003 | 2025-02-24 04:56:03 | 2025-02-26 06:56:03 | 2025-03-04 06:56:03 |
| 3 | 3 | bank_transfer | internal | 88.66 | USD | captured | TX200004 | 2025-02-13 17:43:43 | 2025-02-14 16:43:43 |
| 3 | 3 | bank_transfer | internal | 88.66 | USD | captured | TX200004 | 2025-02-13 17:43:43 | 2025-02-14 16:43:43 |
| 4 | 4 | card | adyen | 322.87 | USD | captured | TX200005 | 2025-02-07 13:00:50 | 2025-02-09 11:00:50 |
| 4 | 4 | card | adyen | 322.87 | USD | captured | TX200005 | 2025-02-07 13:00:50 | 2025-02-09 11:00:50 |
| 5 | 5 | bank_transfer | stripe | 629.34 | USD | captured | TX200006 | 2025-06-24 03:59:58 | 2025-06-26 01:59:58 |
| 5 | 5 | bank_transfer | stripe | 629.34 | USD | captured | TX200006 | 2025-06-24 03:59:58 | 2025-06-26 01:59:58 |
| USD |
| USD |
2. Filtering:
2. Filtering:
delivery_date within the last 90 days relative to todaycapture_timecapture_time)delivery_date within the last 90 days relative to todaycapture_timecapture_time)3. Ordering:
3. Ordering:
delivery_date (descending, most recent first)order_id (ascending)delivery_date (descending, most recent first)order_id (ascending)| Austin |
| Austin |
| TX |
| TX |
| US |
| US |
| economy |
| economy |
| 601.53 |
| 601.53 |
| 5.99 |
| 5.99 |
| 54.96 |
| 54.96 |
| 0.0 |
| 0.0 |
| 662.48 |
| 662.48 |
| partial_refund |
| partial_refund |
| 2025-02-24 04:56:03 |
| 2025-02-24 04:56:03 |
| 3 | ORD-10003 | 21 | 2025-02-13 17:43:43 | shipped | ship | London | ENG | UK | expedited | 68.26 | 14.99 | 5.41 | 0.0 | 88.66 | captured | 2025-02-13 17:43:43 |
| 3 | ORD-10003 | 21 | 2025-02-13 17:43:43 | shipped | ship | London | ENG | UK | expedited | 68.26 | 14.99 | 5.41 | 0.0 | 88.66 | captured | 2025-02-13 17:43:43 |
| 4 | ORD-10004 | 8 | 2025-02-07 13:00:50 | shipped | ship | Calgary | AB | CA | standard | 290.99 | 5.0 | 26.88 | 0.0 | 322.87 | captured | 2025-02-07 13:00:50 |
| 4 | ORD-10004 | 8 | 2025-02-07 13:00:50 | shipped | ship | Calgary | AB | CA | standard | 290.99 | 5.0 | 26.88 | 0.0 | 322.87 | captured | 2025-02-07 13:00:50 |
| 5 | ORD-10005 | 8 | 2025-06-24 03:59:58 | packed | ship | Edmonton | AB | CA | standard | 569.61 | 5.0 | 54.73 | 0.0 | 629.34 | captured | 2025-06-24 03:59:58 |
| 5 | ORD-10005 | 8 | 2025-06-24 03:59:58 | packed | ship | Edmonton | AB | CA | standard | 569.61 | 5.0 | 54.73 | 0.0 | 629.34 | captured | 2025-06-24 03:59:58 |