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.
Products Table: Contains the dimensions of each product in feet.
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.
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
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.
π‘
Explanation
AI Ready
π‘ Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code