不知道是不是我一个人觉得题描述的有点问题。
with tiaojian as (
select 
订单号
from 订单表 d inner join 品类表 p 
on d.商品号=p.商品号
where
优惠券码=01
and
商品类型="B"
)


select 
count(distinct t.订单号) as 总单数,
sum(d.支付金额) as 总金额
from tiaojian t left join 订单表 d 
on t.订单号=d.订单号