#32

Orders Shipped Within 3 Days

EASYAggregation & WindowsPOSTGRESQL

Problem Description

You are analyzing shipping performance for an e-commerce platform. For each customer, calculate the percentage of their orders that were shipped within 3 days of the order date. An order qualifies if the earliest shipment date (`shipdate`) minus the order date (`orderdate`) is 3 days or fewer. Orders with no shipment record should be counted as not shipped within 3 days. If an order has multiple shipment records, use the earliest `shipdate`. **Schema columns:** `customers.customerid`, `orders.orderid`, `orders.customerid`, `orders.orderdate`, `shipments.orderid`, `shipments.shipdate` **Output columns:** `customerid`, `percentage_shipped_within_3_days` Return each `customerid` and their percentage (rounded to 2 decimal places), ordered by percentage descending then `customerid` ascending.

Topics

aggregationdate functionsjoinspercentage calculation

Asked at Companies

amazon

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →