将聚合函数与来自多个表的分组依据一起使用

Use aggregate functions with group by from several tables

我有以下 table 允许订阅者通过应用程序销售产品

订单Table

订单号 日期
1 2021-07-10
2 2021-08-24

批准table

ApprovalId 订单号 状态 SellerId
1 1 已接受 10
2 1 已拒绝 20
3 2 已接受 30

项目table

项目编号 订单号 价格 数量 SellerId
1 1 620$ 1 10
2 1 150$ 2 10
3 1 410$ 1 20
4 2 220$ 1 30

我想要的是显示> 只有接受订单的人的收入

日期 销售额 Seller_Part 90% Net_Sales 10%
2021-07-10 770$ 693$ 77$
2021-08-24 220$ 198% 22$

我尝试将聚合函数与 group by 结合使用,但结果也包括被拒绝的订单

select o.date
  ,sum(i.price * i.qty) sales 
  ,sum(i.price * i.qty) * 0.90 Seller_Part90% 
  ,sum(i.price * i.qty) * 0.10 Net_Sales10% 
from Order o
join Approval a 
  on o.orderId = a.OrderId
  and a.status= 'Accepted'
join Items i
 on a.sellerid = i.sellerid  
 and a.orderid = i.orderid
group by o.date