代码拉取完成,页面将自动刷新
# $1677. 发票中的产品金额
# https://leetcode.cn/problems/products-worth-over-invoices/
# SQL架构
Create table If Not Exists Product(product_id int, name varchar(15));
Create table If Not Exists Invoice(invoice_id int,product_id int,rest int, paid int, canceled int, refunded int);
Truncate table Product;
insert into Product (product_id, name) values ('0', 'ham');
insert into Product (product_id, name) values ('1', 'bacon');
Truncate table Invoice;
insert into Invoice (invoice_id, product_id, rest, paid, canceled, refunded) values ('23', '0', '2', '0', '5', '0');
insert into Invoice (invoice_id, product_id, rest, paid, canceled, refunded) values ('12', '0', '0', '4', '0', '3');
insert into Invoice (invoice_id, product_id, rest, paid, canceled, refunded) values ('1', '1', '1', '1', '0', '1');
insert into Invoice (invoice_id, product_id, rest, paid, canceled, refunded) values ('2', '1', '1', '0', '1', '1');
insert into Invoice (invoice_id, product_id, rest, paid, canceled, refunded) values ('3', '1', '0', '1', '1', '1');
insert into Invoice (invoice_id, product_id, rest, paid, canceled, refunded) values ('4', '1', '1', '1', '1', '0');
# Write your MySQL query statement below
select
p.name,
ifnull(sum(i.rest), 0) as rest,
ifnull(sum(i.paid), 0) as paid,
ifnull(sum(i.canceled), 0) as canceled,
ifnull(sum(i.refunded), 0) as refunded
from
Product p
left join Invoice i on p.product_id = i.product_id
group by
p.product_id,
p.name
order by
p.name;
# clean-up
drop table Product;
drop table Invoice;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。