Skip to content

Commit b5ab699

Browse files
committed
feat(leetcode/easy/1571-warehouse-manager.sql)
1 parent d143195 commit b5ab699

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# 1571-warehouse-manager
2+
# leetcode/easy/1571. Warehouse Manager
3+
# Difficulty: easy
4+
# URL: https://leetcode.com/problems/warehouse-manager/
5+
#
6+
# Input:
7+
# Warehouse table:
8+
# +------------+--------------+-------------+
9+
# | name | product_id | units |
10+
# +------------+--------------+-------------+
11+
# | LCHouse1 | 1 | 1 |
12+
# | LCHouse1 | 2 | 10 |
13+
# | LCHouse1 | 3 | 5 |
14+
# | LCHouse2 | 1 | 2 |
15+
# | LCHouse2 | 2 | 2 |
16+
# | LCHouse3 | 4 | 1 |
17+
# +------------+--------------+-------------+
18+
# Products table:
19+
# +------------+--------------+------------+----------+-----------+
20+
# | product_id | product_name | Width | Length | Height |
21+
# +------------+--------------+------------+----------+-----------+
22+
# | 1 | LC-TV | 5 | 50 | 40 |
23+
# | 2 | LC-KeyChain | 5 | 5 | 5 |
24+
# | 3 | LC-Phone | 2 | 10 | 10 |
25+
# | 4 | LC-T-Shirt | 4 | 10 | 20 |
26+
# +------------+--------------+------------+----------+-----------+
27+
# Output:
28+
# +----------------+------------+
29+
# | warehouse_name | volume |
30+
# +----------------+------------+
31+
# | LCHouse1 | 12250 |
32+
# | LCHouse2 | 20250 |
33+
# | LCHouse3 | 800 |
34+
# +----------------+------------+
35+
# Explanation:
36+
# Volume of product_id = 1 (LC-TV), 5x50x40 = 10000
37+
# Volume of product_id = 2 (LC-KeyChain), 5x5x5 = 125
38+
# Volume of product_id = 3 (LC-Phone), 2x10x10 = 200
39+
# Volume of product_id = 4 (LC-T-Shirt), 4x10x20 = 800
40+
# LCHouse1: 1 unit of LC-TV + 10 units of LC-KeyChain + 5 units of LC-Phone.
41+
# Total volume: 1*10000 + 10*125 + 5*200 = 12250 cubic feet
42+
# LCHouse2: 2 units of LC-TV + 2 units of LC-KeyChain.
43+
# Total volume: 2*10000 + 2*125 = 20250 cubic feet
44+
# LCHouse3: 1 unit of LC-T-Shirt.
45+
# Total volume: 1*800 = 800 cubic feet.
46+
47+
# SELECT warehouse_name, SUM(volume) AS volume
48+
# FROM
49+
50+
51+
SELECT name AS warehouse_name, SUM(units * volume) AS volume
52+
FROM Warehouse
53+
LEFT JOIN (SELECT product_id, (Width * Length * Height) AS volume
54+
FROM Products) AS P ON Warehouse.product_id = P.product_id
55+
GROUP BY name;

0 commit comments

Comments
 (0)