如何在sql server 2008中编写行到列的查询?
我有表客户,
customerno sname contactid address
1 aaa 101 north
1 bbb 102 south
1 ccc 103 west
2 ddd 104 south
2 ccc 105 north
2 eee 106 null
我想将特定客户详细信息转换为单行。 我想要结果,比如
Customerno sname1 sname2 sname3 address1 address2 address3
1 aaa bbb ccc north south west
2 ddd ccc eee south north null
帮助我........
I have table customer
customerno sname contactid address
1 aaa 101 north
1 bbb 102 south
1 ccc 103 west
2 ddd 104 south
2 ccc 105 north
2 eee 106 null
i want to convert particular customer detail into single line.
i want result like
Customerno sname1 sname2 sname3 address1 address2 address3
1 aaa bbb ccc north south west
2 ddd ccc eee south north null
help me ........
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这本质上与下面的问题非常相似。请查看答案以获取指导。由于您要“旋转”超过 1 列,因此我认为这个问题只能通过大量自连接来解决。
将行转换为列
不是为了偏见,这是我的答案:) ...
将行转换为列
This is very similar in nature to the question below. Please look at the answers for guidance. Since you are "pivoting" across more than 1 column, I think this problem can only be solved with a number of self joins.
Convert rows to columns
Not to bias you, here is my answer :) ...
Convert rows to columns