如何在sql server 2008中编写行到列的查询?

发布于 2024-10-04 15:01:22 字数 621 浏览 0 评论 0原文

我有表客户,

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-10-11 15:01:22

这本质上与下面的问题非常相似。请查看答案以获取指导。由于您要“旋转”超过 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文