1677 发票中的产品金额
作者:互联网
题目描述:
要求写一个SQL查询,对于所有产品,返回每个产品的产品名称,以及全部发票累计的总应缴款项、总已支付金额、总已取消金额、总已退款金额。
查询结果按 product_name 排序
示例:
方法1:
主要思路:解题链接汇总
select p.name as 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 as p left join Invoice as i on p.product_id=i.product_id
group by p.name
order by p.name
标签:总已,product,name,ifnull,sum,金额,发票,1677 来源: https://blog.csdn.net/weixin_44171872/article/details/120111844