查询以获取表中特定列的所有值(使用逗号分隔符)到字符串类型数组中 [英] query to get all the values of a particular column in a table(using comma seperator) into string type array

查看:292
本文介绍了查询以获取表中特定列的所有值(使用逗号分隔符)到字符串类型数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好

我的疑问是我的数据库中有一个名为userinfo的表,其中一列为SenderId.现在我想使用逗号分隔符将SenderId列的所有值转换为字符串类型的数组.请告诉我如何编写在mysql中查询此内容.

在此先感谢

Hi Good Evening

My doubt is i have a table called userinfo in my database with one of the column as SenderId.Now i want to get all the values of the SenderId column into a string type array using comma seperator.Can you please tell me how to write the query for this in mysql.

Thanks in advance

推荐答案

DECLARE @Output varchar(max) = ''
SELECT @Output = coalesce(@Output+',','') + CONVERT(varchar(max),Col1) FROM Table1
SET @Output = RIGHT(@Output,LEN(@Output)-1)
PRINT @Output


像这样:

like this:

SELECT GROUP_CONCAT(SenderID) FROM UserInfo


这篇关于查询以获取表中特定列的所有值(使用逗号分隔符)到字符串类型数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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