帮助 PIVOT

发布于 2024-08-16 14:46:20 字数 526 浏览 5 评论 0原文

我有一个表格如下

Name        |          Words
A              words for A1 here
B              words for B1 here
C               words for C1 here
A               words for A2 here
B               words for B2 here
C               words for C2 here

我想旋转上面的表格以获得以下结果

A                    |      B                 |       C
words for A1 here       words for B1 here         words for C1 here
words for A2 here       words for B2 here         words for C2 here

谢谢

I have a table as follows

Name        |          Words
A              words for A1 here
B              words for B1 here
C               words for C1 here
A               words for A2 here
B               words for B2 here
C               words for C2 here

I want to pivot the above table to get the following result

A                    |      B                 |       C
words for A1 here       words for B1 here         words for C1 here
words for A2 here       words for B2 here         words for C2 here

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

盛装女皇 2024-08-23 14:46:20
With Numbered as
(
select *, ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Words) AS RowNum
from yourTable)
select [A],[B],[C]
from Numbered n
pivot (max(Words) for Name in ([A],[B],[C])) p
;
With Numbered as
(
select *, ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Words) AS RowNum
from yourTable)
select [A],[B],[C]
from Numbered n
pivot (max(Words) for Name in ([A],[B],[C])) p
;
毁梦 2024-08-23 14:46:20
select A, B, C from
(
  select Name, CAST(Words as nvarchar(1000)) as Words from DemoTable
) up
pivot (Max(words) for Name in (A, B, C)) as pvt
select A, B, C from
(
  select Name, CAST(Words as nvarchar(1000)) as Words from DemoTable
) up
pivot (Max(words) for Name in (A, B, C)) as pvt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文