select a.部门代码
,[销售方式1销售数量]=sum(case a.销售方式 when 0 then a.销售数量 else 0 end)
,[销售方式2销售数量]=sum(case a.销售方式 when 1 then a.销售数量 else 0 end)
,是优秀品牌销售数量=sum(case b.是否优秀品牌 when 1 then a.销售数量 else 0 end)
from 表1 a join 表2 b on a.销售品牌=b.销售品牌
group by a.部门代码