代码拉取完成,页面将自动刷新
# $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;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。