日期:2014-05-17 浏览次数:20786 次
create table groups(member varchar(10),type varchar(10), cost int) insert into groups select '甲','A',2000 union all select '乙','B',1000 union all select '丙','B',2000 union all select '丁','B',3000 SELECT A as A状态下Cost, B as B状态下Cost FROM (select type,cost from groups)a PIVOT (SUM(COST) FOR TYPE IN(A,B))p /* A状态下Cost B状态下Cost ----------- ----------- 2000 6000 (1 行受影响) */