You are given two tables: Warehouse and Products.
The Warehouse table contains information about products stored in each warehouse, including the warehouse name, product ID, and number of units.
The Products table contains product dimensions (Width, Length, and Height) in feet for each product.
Write a SQL query to calculate the total volume in cubic feet that the inventory occupies in each warehouse. The volume of each product is calculated as Width × Length × Height, and the total volume per warehouse is the sum of (volume × units) for all products in that warehouse.
Return the result table in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
name
PK
|
varchar | Warehouse name |
product_id
PK
|
int | Product identifier |
units
|
int | Number of units stored |
| Column Name | Type | Description |
|---|---|---|
product_id
PK
|
int | Product identifier |
product_name
|
varchar | Product name |
Width
|
int | Product width in feet |
Length
|
int | Product length in feet |
Height
|
int | Product height in feet |
Input & Output
| name | product_id | units |
|---|---|---|
| LCHouse1 | 1 | 1 |
| LCHouse1 | 2 | 10 |
| LCHouse1 | 3 | 5 |
| LCHouse2 | 1 | 2 |
| LCHouse2 | 2 | 2 |
| LCHouse3 | 4 | 1 |
| 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-T-Shirt | 4 | 10 | 20 |
| warehouse_name | volume |
|---|---|
| LCHouse1 | 12250 |
| LCHouse2 | 20250 |
| LCHouse3 | 800 |
For each warehouse, we calculate the total volume by multiplying each product's dimensions (Width × Length × Height) by the number of units, then summing all products in that warehouse.
LCHouse1: (1×5×50×40) + (10×5×5×5) + (5×2×10×10) = 10000 + 1250 + 1000 = 12250
LCHouse2: (2×5×50×40) + (2×5×5×5) = 20000 + 250 = 20250
LCHouse3: (1×4×10×20) = 800
| name | product_id | units |
|---|---|---|
| Warehouse1 | 1 | 3 |
| product_id | product_name | Width | Length | Height |
|---|---|---|---|---|
| 1 | Product1 | 2 | 3 | 4 |
| warehouse_name | volume |
|---|---|
| Warehouse1 | 72 |
Simple case with one warehouse and one product. Volume = 3 units × (2×3×4) = 3 × 24 = 72 cubic feet.
Constraints
-
1 ≤ units ≤ 1000 -
1 ≤ Width, Length, Height ≤ 100 -
product_idis unique in Products table -
(name, product_id)is unique in Warehouse table