sql server pivot 用法(SQL Server 的支点用法)
Explain the usage of PIVOT/UNPIVOT through two examples
Release time: 2008. 03. sql server pivot 用法(SQL Server 的支点用法)
Explain the usage of PIVOT/UNPIVOT through two examples
Release time: 2008. 03. 13 04:58 source: CCID, author: ChenJaYi
[reports] CCIDNET IT technology used SQL Server 2000 of the people know, in order to achieve the ranks of the conversion, must use aggregate functions and dynamic SQL, specific implementation requires certain skills, while in SQL Server 2005, using the new keyword PIVOT/UNPIVOT, you can easily achieve the ranks of the conversion requirements.
In this article, we' 11 explain the usage of PIVOT/UNPIVOT in two simple examples.
The use of PIVOT:
First, create the test table and then insert the test data
Create, table, test (ID, int, profile, int)
name, varchar (20), quarter, int,
Insert, into, test, values
(l,'a‘,11000)
Insert, into, test, values
(l,'a‘,22000)
Insert, into, test, values
(l,'a‘,34000)
Insert, into, test, values
(l,'a‘,45000)
Insert, into, test, values (2,' b' , 13000)
Insert, into, test, values (2,' b' , 23500)
Insert, into, test, values (2,' b' , 34200)
Insert, into, test, values (2,' b' , 45500)
Select * from test
ID name quarter profile
1 a 11000
1 a 22000
1 a 34000
a 45000
B 13000
2 B 23500
2 B 34200
2 B 45500 (8, row (s) affected)
Use PIVOT to convert four
sqlserverpivot用法SQLServer的支点用法 来自淘豆网www.taodocs.com转载请标明出处.