SQL 行转列示例
--油表 select (select SUM(XiaoHaoLiang)as'油表消耗总值' FROM dbo.NengHaoYouBiao WHERE CaiJiRiQi between '2013-01-01' and '2013-12-30') as '油表消耗总值', --水表 (select SUM(XiaoHaoZhi)as'水表消耗总值' FROM dbo.NengHaoShuiBiao WHERE CaiJiRiQi between '2013-01-01' and '2013-12-30') as '水表消耗总值', --气表 (select SUM(XiaoHaoZhi)as'气表消耗总值' from dbo.NengHaoQiBiao WHERE CaiJiRiQi between '2013-01-01' and '2013-12-30') as '气表消耗总值', --电表 ( select SUM(XiaoHaoZhi)as'气表消耗总值' from dbo.nhcjDetail_dian WHERE caijiDate between '2013-01-01' and '2013-12-30') as '气表消耗总值' 语法: select (select num1 from a)as ‘1列’,(select num1 from a)as ‘2列’,(select num1 from a)as ‘3列’