LeetCode:Database 115.仓库经理
要求:写一个 SQL 查询来报告, 每个仓库的存货量是多少立方英尺。
表: Warehouse的结构
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| name | varchar |
| product_id | int |
| units | int |
+--------------+---------+
(name, product_id) 是该表主键.
该表的行包含了每个仓库的所有商品信息.
表: Products的结构
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| product_name | varchar |
| Width | int |
| Length | int |
| Height | int |
+---------------+---------+
product_id 是该表主键.
该表的行包含了每件商品以英尺为单位的尺寸(宽度, 长度和高度)信息.
Warehouse 表:
+------------+--------------+-------------+
| name | product_id | units |
+------------+--------------+-------------+
| LCHouse1 | 1 | 1 |
| LCHouse1 | 2 | 10 |
| LCHouse1 | 3 | 5 |
| LCHouse2 | 1 | 2 |
| LCHouse2 | 2 | 2 |
| LCHouse3 | 4 | 1 |
+------------+--------------+-------------+
Products 表:
+------------+--------------+------------+----------+-----------+
| 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 |
+------------+--------------+------------+----------+-----------+
Result Table:
+----------------+------------+
| WAREHOUSE_NAME | VOLUME |
+----------------+------------+
| LCHouse1 | 12250 |
| LCHouse2 | 20250 |
| LCHouse3 | 800 |
+----------------+------------+
Id为1的商品(LC-TV)的存货量为 5x50x40 = 10000
Id为2的商品(LC-KeyChain)的存货量为 5x5x5 = 125
Id为3的商品(LC-Phone)的存货量为 2x10x10 = 200
Id为4的商品(LC-T-Shirt)的存货量为 4x10x20 = 800
仓库LCHouse1: 1个单位的LC-TV + 10个单位的LC-KeyChain + 5个单位的LC-Phone.总存货量为: 1*10000 + 10*125 + 5*200 = 12250 立方英尺
仓库LCHouse2: 2个单位的LC-TV + 2个单位的LC-KeyChain.总存货量为: 2*10000 + 2*125 = 20250 立方英尺
仓库LCHouse3: 1个单位的LC-T-Shirt.总存货量为: 1*800 = 800 立方英尺.
SQL语句:
with a as(
select product_id,width*length*height as
area
from products
)select b.name as WAREHOUSE_NAME,sum(b.units*a.area) as VOLUME
from a
join warehouse b
on a.product_id=b.product_id
group by b.name;
LeetCode:Database 115.仓库经理相关推荐
- LeetCode MySQL 1571. 仓库经理
1. 题目 表: Warehouse +--------------+---------+ | Column Name | Type | +--------------+---------+ | na ...
- LeetCode Database知识点总结 - 1587
LeetCode 1587. Bank Account Summary II 考点 难度 Database Easy 题目 Write an SQL query to report the name ...
- LeetCode Database知识点总结 - 1757
LeetCode 1757. Recyclable and Low Fat Products 考点 难度 Database Easy 题目 Write an SQL query to find the ...
- LeetCode Database知识点总结 - 1667
LeetCode 1667. Fix Names in a Table 考点 难度 Database Easy 题目 Write an SQL query to fix the names so th ...
- 【Leetcode】115. Distinct Subsequences
又是一道DP的题目,个人感觉DP的题目比较难,主要因为:(1)DP的难点是寻找子问题,如果找到很好的子问题,那么就可以瞬间搞定.(2)通常也会带有一点backtracking的思想,有时候总是优先想到 ...
- 【leetcode Database】175.Combine Two Tables
题目: Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | Perso ...
- 【leetcode Database】184. Department Highest Salary
题目: The Employee table holds all employees. Every employee has an Id, a salary, and there is also a ...
- LeetCode数据库SQL题目记录(难度:简单)
难度:简单 目录 175. 组合两个表 176. 第二高的薪水 181. 超过经理收入的员工 182. 查找重复的电子邮箱 183. 从不订购的客户 196. 删除重复的电子邮箱 197. 上升的温度 ...
- LeetCode 之 JavaScript 解答第20题 —— 有效的括号(Valid Parentheses)
Time:2019/4/11 Title: Valid Parentheses Difficulty: Easy Author: 小鹿 题目:Valid Parentheses Given a str ...
最新文章
- 【BIEE】BI Publisher下拉菜单设置
- c拆分字符串,并按照指定格式存入结构体数组
- 012_html如何查看源代码
- 天池 O2O 优惠券使用预测思路解析与代码实战
- 五十、Maven系列:安装和配置Maven镜像
- 怎样正确使用和维护微型计算机,下篇:微型计算机应该怎样进行维护与保养
- 灵魂拷问!一起刷完了这份1307页的安卓面试宝典吧,不吃透都对不起自己
- 李飞飞团队发布:中国AI期刊影响力首超美国
- java中json对象去重复_如何忽略Java中JSON对象的多个属性?
- 4周第4次课 压缩打包介绍 gzip bzip2 xz压缩工具
- JavaScript学习(七)
- 2B: 怎么把黑科技卖给顶级金融机构? | 甲子光年
- matlab读取txt函数,matlab读取txt某一行
- WPSOffice双面文档打印边距设置技巧(转)
- Linux内核内存管理(2):固定映射地址(fixmap)和输入输出重映射(ioremap)
- Tomcat安装及配置详解
- 怎么用python处理word和excel_用python操作word excel
- 算法-蓝桥杯习题(3-1)
- 中文完整版FL Studio21永久免费升级
- $.each(json,function(index,item){ }); jquery遍历