88. Warehouse Stock Manager

As a warehouse manager, you need to track how much physical space is occupied by products in each warehouse. This is crucial for logistics, expansion planning, and inventory control. You are given two tables:

Warehouse

╔═════════════╦══════════╗
β•‘ Column Name β•‘   Type   β•‘
╠═════════════╬══════════╣
β•‘    name     β•‘ varchar  β•‘
║─────────────┼──────────║
β•‘ product_id  β•‘   int    β•‘
║─────────────┼──────────║
β•‘    units    β•‘   int    β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•
  • name: Name of the warehouse
  • product_id: ID of the product stored in the warehouse (foreign key to Products)
  • units: Number of units of the product stored in that warehouse
  • (name, product_id) is the primary key

Products

╔═════════════╦══════════╗
β•‘ Column Name β•‘   Type   β•‘
╠═════════════╬══════════╣
β•‘ product_id  β•‘   int    β•‘
║─────────────┼──────────║
β•‘product_name β•‘ varchar  β•‘
║─────────────┼──────────║
β•‘    Width    β•‘   int    β•‘
║─────────────┼──────────║
β•‘   Length    β•‘   int    β•‘
║─────────────┼──────────║
β•‘   Height    β•‘   int    β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•
  • product_id: Unique ID for the product (Primary Key)
  • product_name: Name of the product
  • Width: Width of the product in feet
  • Length: Length of the product in feet
  • Height: Height of the product in feet

Write a query to calculate the total volume (in cubic feet) occupied by the inventory in each warehouse. The result can be returned in any order.

Example 1:

Example:

Input:

Warehouse Table

╔═══════════╦════════════╦═══════╗
β•‘    name   β•‘ product_id β•‘ units β•‘
╠═══════════╬════════════╬═══════╣
β•‘ VCHouse1  β•‘     1      β•‘   1   β•‘
║───────────┼────────────┼───────║
β•‘ VCHouse1  β•‘     2      β•‘  10   β•‘
║───────────┼────────────┼───────║
β•‘ VCHouse1  β•‘     3      β•‘   5   β•‘
║───────────┼────────────┼───────║
β•‘ VCHouse2  β•‘     1      β•‘   2   β•‘
║───────────┼────────────┼───────║
β•‘ VCHouse2  β•‘     2      β•‘   2   β•‘
║───────────┼────────────┼───────║
β•‘ VCHouse3  β•‘     4      β•‘   1   β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•

Products Table

╔════════════╦══════════════╦═══════╦════════╦════════╗
β•‘ product_id β•‘ product_name β•‘ Width β•‘ Length β•‘ Height β•‘
╠════════════╬══════════════╬═══════╬════════╬════════╣
β•‘     1      β•‘    VC-TV     β•‘   5   β•‘   50   β•‘   40   β•‘
║────────────┼──────────────┼───────┼────────┼────────║
β•‘     2      β•‘ VC-KeyChain  β•‘   5   β•‘    5   β•‘    5   β•‘
║────────────┼──────────────┼───────┼────────┼────────║
β•‘     3      β•‘  VC-Phone    β•‘   2   β•‘   10   β•‘   10   β•‘
║────────────┼──────────────┼───────┼────────┼────────║
β•‘     4      β•‘ VC-T-Shirt   β•‘   4   β•‘   10   β•‘   20   β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•

Expected Output:

╔════════════════╦════════╗
β•‘ warehouse_name β•‘ volume β•‘
╠════════════════╬════════╣
β•‘   VCHouse1     β•‘ 12250  β•‘
║────────────────┼────────║
β•‘   VCHouse2     β•‘ 20250  β•‘
║────────────────┼────────║
β•‘   VCHouse3     β•‘  800   β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•

Explanation:

Calculate volume per product using: Width Γ— Length Γ— Height

  • VC-TV = 5Γ—50Γ—40 = 10000
  • VC-KeyChain = 5Γ—5Γ—5 = 125
  • VC-Phone = 2Γ—10Γ—10 = 200
  • VC-T-Shirt = 4Γ—10Γ—20 = 800

Now, compute total volume per warehouse:

  • VCHouse1: 1Γ—10000 + 10Γ—125 + 5Γ—200 = 12250
  • VCHouse2: 2Γ—10000 + 2Γ—125 = 20250
  • VCHouse3: 1Γ—800 = 800

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
Β 
Test Case

Input:

Warehouse
Products