日期:2014-05-18 浏览次数:20471 次
select 'N1' as Col,sum(a1) from table1 union all select 'N2' as Col,sum(a2) from table1 union all select 'N3' as Col,sum(a3) from table1
------解决方案--------------------
select 'N1',sum(a1) union all
select 'N2',sum(a2) union all
select 'N3',sum(a3)
------解决方案--------------------
select 'N1' as N,sum(a1) AS [SUM] from table1 union all select 'N2' as N,sum(a2) from table1 union all select 'N3' as N,sum(a3) from table1 --or SELECT * FROM (SELECT SUM(a1) AS N1,SUM(a2) AS N2,SUM(a3) AS N3) AS a PIVOT ([Sum] FOR N IN(N1,N2,N3)) AS b
------解决方案--------------------
select N='N1',[sum]=sum(a1) from table1 union all select 'N2',sum(a2) from table1 union all select 'N3',sum(a3) from table1