Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-1715.test 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 2022-05-22 00:04 +08:00 . fix lc-1715.test
# $1715. 苹果和橘子的个数
# https://leetcode.cn/problems/count-apples-and-oranges/
# SQL架构
Create table If Not Exists Boxes (box_id int, chest_id int, apple_count int, orange_count int);
Create table If Not Exists Chests (chest_id int, apple_count int, orange_count int);
Truncate table Boxes;
insert into Boxes (box_id, chest_id, apple_count, orange_count) values ('2', null, '6', '15');
insert into Boxes (box_id, chest_id, apple_count, orange_count) values ('18', '14', '4', '15');
insert into Boxes (box_id, chest_id, apple_count, orange_count) values ('19', '3', '8', '4');
insert into Boxes (box_id, chest_id, apple_count, orange_count) values ('12', '2', '19', '20');
insert into Boxes (box_id, chest_id, apple_count, orange_count) values ('20', '6', '12', '9');
insert into Boxes (box_id, chest_id, apple_count, orange_count) values ('8', '6', '9', '9');
insert into Boxes (box_id, chest_id, apple_count, orange_count) values ('3', '14', '16', '7');
Truncate table Chests;
insert into Chests (chest_id, apple_count, orange_count) values ('6', '5', '6');
insert into Chests (chest_id, apple_count, orange_count) values ('14', '20', '10');
insert into Chests (chest_id, apple_count, orange_count) values ('2', '8', '8');
insert into Chests (chest_id, apple_count, orange_count) values ('3', '19', '4');
insert into Chests (chest_id, apple_count, orange_count) values ('16', '19', '19');
# Write your MySQL query statement below
select
ifnull(sum(b.apple_count), 0) + ifnull(sum(c.apple_count), 0) as apple_count,
ifnull(sum(b.orange_count), 0) + ifnull(sum(c.orange_count), 0) as orange_count
from
Boxes b
left join Chests c on b.chest_id = c.chest_id;
# clean-up
drop table Boxes;
drop table Chests;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助