sql server pivot

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[YearSalary](
    [year] [int] NULL,
    [salary] [money] NULL
) ON [PRIMARY]
GO


select * from yearsalary;

select 'year' as WorkYear,[2011],[2012],[2013],[2014],[2015],[2016],[2017],[2018],[2019]
from 
(
select year,salary  from yearsalary) as SourceTable
pivot
(
avg(salary)
for year in([2011],[2012],[2013],[2014],[2015],[2016],[2017],[2018],[2019])
) as pivottable

 

 

 

posted @ 2019-09-08 15:16  FredGrit  阅读(315)  评论(0编辑  收藏  举报