select 部门,sum(产品1) as 产品1,sum(产品2) as 产品2,sum(产品3) as 产品3 from
(select a as 部门,(case B when '产品1' then sum(c) else 0 end) as 产品1,
(case B when '产品2' then sum(c) else 0 end) as 产品2,
(case B when '产品3' then sum(c) else 0 end) as 产品3 from Table_2 group by A,b) as t group by 部门
你的部门和产品如果是固定的,就按楼上的写
如果不是固定的,SQL语法会复杂一点
如果是用.net去实现,会简单不少
面试就会搞这些- -!我当初也碰过。还有筛选重复数据的。。等等
行转列!百度一下很简单的!