以逗号分隔显示数据 [英] show data in comma separated

查看:179
本文介绍了以逗号分隔显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有名字



1800 t1

1800 t2

1800 t3

1800 t4

1800 t5

1900 t6

1900 t7

1900 t8

2000 t100



我的数据(如上所述)在表格中

我想做的是

i想要显示它(以逗号分隔值)





1800 t1,t1,t3,t4,t5

1900 t6,t7,t8

2000 t100



查询得到的结果如下所示



注意:我有数百甚至数千的数据。它只是一个清除事物的光环

no name

1800 t1
1800 t2
1800 t3
1800 t4
1800 t5
1900 t6
1900 t7
1900 t8
2000 t100

I have data ( like above mentioned ) in table
what i want to do is
i want to show it to like this ( in comma separated value )

no
1800 t1,t1,t3,t4,t5
1900 t6,t7,t8
2000 t100

what the query to get result l like this

note : i have data in hundreds or even thousands. its just a sampple to clear things

推荐答案

试试这个:(注意Table_1是你的表名。)



Hi, try this: (Note that Table_1 is your table name.)

SELECT
DISTINCT r.no,
       STUFF((SELECT DISTINCT ','+ a.name
              FROM Table_1 a
              WHERE r.no = a.no
              FOR XML PATH(''), TYPE).value('.','VARCHAR(max)'), 1, 1, '')
FROM Table_1 r





我自己尝试过,它正在运行。



I tried it by myself, and it's working.


这篇关于以逗号分隔显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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