将列排成行 [英] Arrange the column as row

查看:70
本文介绍了将列排成行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Input

1   26019   2013-03-21 00:00:00 9.25    O
2   26019   2013-03-21 00:00:00 10.11   I
4   26019   2013-03-21 00:00:00 10.12   O
3   26019   2013-03-21 00:00:00 17.06   I
5   26019   2013-03-21 00:00:00 21.00   O


Output 

1  26019	2013-03-21 00:00:00  9.25  10.11
2  26019	2013-03-21 00:00:00  10.12 17.06

推荐答案

如果您有固定数量的时间列,则可以使用PIVOT。请参阅此处的示例: http://msdn.microsoft.com/en-us /library/ms177410(v=sql.105).aspx [ ^ ]

或者,如果是动态数字,请检查: http://blog-mstechnology.blogspot.fr/2010/06/t-sql-pivot-operator-with- dynamic.html [ ^ ]
You can use PIVOT if you will have fixed number of "time" columns. See sample here: http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx[^]
Or, if it is a dynamic number, check this: http://blog-mstechnology.blogspot.fr/2010/06/t-sql-pivot-operator-with-dynamic.html[^]


http://sqlserveradvisor.blogspot.in/2009/03/sql-server-convert-rows-to-columns.html [ ^ ]



http://stackoverflow.com/questions/11323024/how-to-convert-columns-to-rows-in-sql-server [ ^ ]


这篇关于将列排成行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆