将列转换为行 [英] Convert Column to Rows

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

问题描述

嗨。
$


任何人都可以帮我实现这个目标。



我有这样的数据



表格列数
Tab1    Col1

Tab1    Col2

Tab1    Col3

Tab2    Col1

Tab2    Col2



输出:



表 专栏

Tab1      Col1,col2,col3

Tab2      Col1,Col2

Hi .

Can anyone help me to achieve this.

I have data like this

Tables Columns
Tab1    Col1
Tab1    Col2
Tab1    Col3
Tab2    Col1
Tab2    Col2

Output:

Tables  Columns
Tab1      Col1,col2,col3
Tab2      Col1,Col2

推荐答案

如果您使用的是SQL Server 2017,则可以使用
STRING_AGG
功能
If you are using SQL Server 2017 then you can used STRING_AGG function


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

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