Sql case when 示例
SELECT
单元编号,年,月, 项目编号='11111',
sum(case when 项目编号= 'ZB010201' then [当月额] else 0 end ) 医疗收入,
sum(case when 项目编号='ZB010202' then [当月额] else 0 end ) 科教收入,
sum(case when 项目编号= 'ZB010201' then [当月额] else 0 end )+sum(case when 项目编号='ZB010202' then [当月额] else 0 end ) 事业收入
FROM [dbo].[Report_ItemData] where 单元编号=5
group by 单元编号,年,月