使用 SQL 2005 Pivot [英] Using SQL 2005 Pivot
本文介绍了使用 SQL 2005 Pivot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要转以下结果...
I need to turn the following results...
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
这可能吗?
推荐答案
有 PIVOT 命令...
There's the PIVOT command...
SELECT *
FROM YourTable
PIVOT (MAX(Value) FOR ColumnName IN ([Status],[Name],[Created])) as p;
这篇关于使用 SQL 2005 Pivot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文