Warehouse Bin Optimization

10pts
Amazon

Problem Statement

Efficiency in Amazon Fulfillment Centers depends on minimizing the travel distance for pickers. When items are frequently bought together but stored in different warehouse zones (e.g., Zone A and Zone C), it forces pickers to travel across the warehouse for a single order.

Write a query to identify pairs of products that have been ordered together in at least 3 separate orders but are currently stored in different warehouse zones.

Rules:

  • A pair is defined as two distinct products appearing in the same order_id.
  • To avoid double-counting pairs (e.g., Item 1 & Item 2 vs Item 2 & Item 1), always list the product with the lower product_id as product_a.
  • Output columns: product_a, product_b, zone_a, zone_b, order_count.
  • Only include pairs where zone_a != zone_b and order_count >= 3.
  • Results must be sorted by order_count descending, then product_a ascending.
Tests your understanding of
Market Basket Analysis, Self Join and Optimization

Input Tables

order_items
order_id(INTEGER)product_id(INTEGER)
1101
1102
2101
2102
3101
3102
4201
4202
5201
5202
6101
6201
warehouse_bins
product_id(INTEGER)warehouse_zone(VARCHAR)
101Zone_A
102Zone_B
201Zone_C
202Zone_C

Expected Output

product_a(INTEGER)product_b(INTEGER)zone_a(VARCHAR)zone_b(VARCHAR)order_count(INTEGER)
101102Zone_AZone_B3

Tags

HardMarket Basket AnalysisSelf JoinOptimization
45-55 min
29%

Hints