Warehouse Manager - Problem
Warehouse Inventory Volume Calculator

You're managing a sophisticated warehouse system that needs to calculate the total volume occupied by inventory in each warehouse.

Given two tables:

Warehouse Table: Contains information about which products are stored in each warehouse and their quantities.
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| name | varchar |
| product_id | int |
| units | int |
+--------------+---------+


Products Table: Contains the dimensions of each product in feet.
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| product_name | varchar |
| Width | int |
| Length | int |
| Height | int |
+---------------+---------+


Goal: Calculate the total cubic feet of volume that the inventory occupies in each warehouse. For each product, multiply its dimensions (Width Γ— Length Γ— Height) by the number of units stored to get the total volume contribution.

Input & Output

example_1.sql β€” Basic Warehouse Calculation
$ Input: Warehouse: | name | product_id | units | |------|------------|-------| | LCHouse1 | 1 | 1 | | LCHouse1 | 2 | 10 | | LCHouse1 | 3 | 5 | | LCHouse2 | 1 | 2 | | LCHouse2 | 2 | 2 | | LCHouse3 | 4 | 1 | Products: | product_id | product_name | Width | Length | Height | |------------|--------------|-------|--------|--------| | 1 | LC-TV | 5 | 50 | 40 | | 2 | LC-KeyChain | 5 | 5 | 5 | | 3 | LC-Phone | 2 | 10 | 10 | | 4 | LC-Book | 4 | 100 | 10 |
β€Ί Output: | warehouse_name | volume | |----------------|--------| | LCHouse1 | 12250 | | LCHouse2 | 10250 | | LCHouse3 | 4000 |
πŸ’‘ Note: LCHouse1: TV(1Γ—5Γ—50Γ—40) + KeyChain(10Γ—5Γ—5Γ—5) + Phone(5Γ—2Γ—10Γ—10) = 10000 + 1250 + 1000 = 12250. LCHouse2: TV(2Γ—5Γ—50Γ—40) + KeyChain(2Γ—5Γ—5Γ—5) = 20000 + 250 = 10250. LCHouse3: Book(1Γ—4Γ—100Γ—10) = 4000.
example_2.sql β€” Single Product Multiple Warehouses
$ Input: Warehouse: | name | product_id | units | |------|------------|-------| | East | 1 | 5 | | West | 1 | 3 | | North | 1 | 2 | Products: | product_id | product_name | Width | Length | Height | |------------|--------------|-------|--------|--------| | 1 | Box | 2 | 2 | 2 |
β€Ί Output: | warehouse_name | volume | |----------------|--------| | East | 40 | | West | 24 | | North | 16 |
πŸ’‘ Note: Each box has volume 2Γ—2Γ—2 = 8 cubic feet. East: 5Γ—8 = 40, West: 3Γ—8 = 24, North: 2Γ—8 = 16.
example_3.sql β€” Empty Warehouse Edge Case
$ Input: Warehouse: | name | product_id | units | |------|------------|-------| | Main | 1 | 0 | | Secondary | 2 | 1 | Products: | product_id | product_name | Width | Length | Height | |------------|--------------|-------|--------|--------| | 1 | Large | 10 | 10 | 10 | | 2 | Small | 1 | 1 | 1 |
β€Ί Output: | warehouse_name | volume | |----------------|--------| | Main | 0 | | Secondary | 1 |
πŸ’‘ Note: Main warehouse has 0 units of the large product, so volume is 0Γ—10Γ—10Γ—10 = 0. Secondary has 1 unit of small product: 1Γ—1Γ—1Γ—1 = 1.

Constraints

  • 1 ≀ number of warehouses ≀ 100
  • 1 ≀ number of products ≀ 1000
  • 0 ≀ units ≀ 105
  • 1 ≀ Width, Length, Height ≀ 1000
  • All product_ids in Warehouse table exist in Products table

Visualization

Tap to expand
πŸ“¦ Warehouse ATVΓ—2PhoneΓ—5BookΓ—3Volume = ?πŸ“‹ Product CatalogTV: 50Γ—40Γ—5Phone: 10Γ—5Γ—2Book: 20Γ—15Γ—3JOIN&CALCπŸ“Š Final ResultWarehouse A:β€’ TV: 2Γ—(50Γ—40Γ—5) = 20,000β€’ Phone: 5Γ—(10Γ—5Γ—2) = 500β€’ Book: 3Γ—(20Γ—15Γ—3) = 2,700Total: 23,200 cubic feet
Understanding the Visualization
1
Match Products to Inventory
Connect each warehouse item with its product dimensions using product_id
2
Calculate Individual Volumes
For each item: multiply Width Γ— Length Γ— Height Γ— Quantity
3
Sum by Warehouse
Group all products by warehouse and add up their total volumes
Key Takeaway
🎯 Key Insight: SQL JOINs efficiently combine related data from multiple tables, allowing us to calculate complex derived values like volume in a single optimized query rather than multiple lookups.
Asked in
Amazon 45 Walmart 32 FedEx 28 UPS 24
28.4K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
πŸ’‘ Explanation
AI Ready
πŸ’‘ Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen