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

 

 

 

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐