SQL里面行转列的意思啊,做了个例子你看看。
原始数据图1,新数据图2,SQL图3
你这题用
select a.月份,sum(a.2019n) as '2019年',sum(a.2018n) as '2018年' from
( select 月份,
(case when 年=2019 then 实际销售额 else 0 end ) as '2019n',
(case when 年=2018 then 实际销售额 else 0 end ) as '2018n'
from 表名 ) a
group by a.月份
图中sql: select a.月份,sum(a.北美1) as '北美',sum(a.亚太1) as '亚太地区' from
( select 月份,
(case when 地区='北美' then 实际销售额 else 0 end ) as '北美1',
(case when 地区='亚太地区' then 实际销售额 else 0 end ) as '亚太1'
from 年度 where 地区 in ('北美','亚太地区') ) a
group by a.月份