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.