gpt4 book ai didi

SQL Server,如何转置列的数据

转载 作者:行者123 更新时间:2023-12-02 13:29:41 25 4
gpt4 key购买 nike

Possible Duplicate:
Concatenate many rows into a single text string?

我有一个疑问

SELECT city FROM cityTable

返回

delhi
faridabad
haryana
mathura
kerla

我只想以转置方式得到结果

delhi | faridabad | haryana | mathura | kera

这怎么可能?

最佳答案

SELECT STUFF (
(SELECT N', ' + city FROM CityTable FOR XML PATH(''),TYPE)
.value('text()[1]','nvarchar(max)'),1,2,N'')

Concatenate many rows into a single text string?

关于SQL Server,如何转置列的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10733141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com