行转列一张表查询结果为--行转列select years,(select amount from Tb_Amount as A where month=1 and A.years=Tb_Amount.years)as m1,(select amount from Tb_Amount as A where month=2 and A.years=Tb_Amount.years)as m2,(select amount from T..
话不多说,请看代码:/*SELECT <非透视的列>, [第一个透视的列] AS <列名称>, [第二个透视的列] AS <列名称>, ... [最后一个透视的列] AS <列名称>,FROM (<生成数据的 SELECT 查询>) AS <源查询的别名>PIVOT( <聚合函数>(<要聚合的列>)FOR[<包含要..