1571. Warehouse Manager

Level: Easy; Amazon

Question:

Table: Warehouse

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| name         | varchar |
| product_id   | int     |
| units        | int     |
+--------------+---------+
(name, product_id) is the primary key for this table.
Each row of this table contains the information of the products in each warehouse.

Table: Products

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| product_id    | int     |
| product_name  | varchar |
| Width         | int     |
| Length        | int     |
| Height        | int     |
+---------------+---------+
product_id is the primary key for this table.
Each row of this table contains information about the 
product dimensions (Width, Lenght, and Height) in feets of each product.

Write an SQL query to report the number of cubic feet of volume the inventory occupies in each warehouse.

Return the result table in any order.

The query result format is in the following example.

Example 1:

My Solution:

First: calculate the volume of each product (e.g. LC-TV, LC-KeyChain, etc.) and append it to each row in Warehouse with corresponding product_id.

Second: calculate the sum of the inventory using group by warehouse name.

Last updated