使用SQL 2005枢轴(Using SQL 2005 Pivot)

2019-09-30 08:11发布

我需要把下面的结果...

RowID   ColumnName   Value
======= ============ ==========
200     Status       OK
200     Name         Project 1
200     Created      01/01/2010 00:00
201     Status       FAILED
201     Name         Project 2
201     Created      02/01/2010 18:00
202     Status       OK
202     Name         Project 3
202     Created      03/01/2010 21:00

...这个...

RowID   Status Name      Created
======= ====== ========= ================
200     OK     Project 1 01/01/2010 00:00
201     FAILED Project 2 02/01/2010 18:00
202     OK     Project 3 03/01/2010 21:00

这可能吗?

Answer 1:

还有的转动命令...

SELECT *
FROM YourTable
PIVOT (MAX(Value) FOR ColumnName IN ([Status],[Name],[Created])) as p;


文章来源: Using SQL 2005 Pivot