SQL按如下处理,最后报表上面商品类别作为最父格,汇总公式的父格设置为商品类别
select
*,
case when "厂家1价格" is not null and "厂家2价格" is not null then '共同商品' else '非共同商品' end as 商品类别
from (
select
商品,
sum(case when 厂家='厂家1' then 价格 end) as "厂家1价格",
sum(case when 厂家='厂家2' then 价格 end) as "厂家2价格"
from 表名
group by 商品
) as P