sqlserver-group by拼接字符串


with
temp00 as (
select
'1' id,
'zhangsan' name,
'gaoshu' cla,
'3' num  
select
'2' id,
'lisi' name,
'gaoshu' cla,
'2' num
union all
select
'2' id,
'lisi' name,
'jingji' cla,
'4' num
union all
select
'3' id,
'wangwu' name,
'gaoshu' cla,
'3' num
union all
select
'3' id,
'wangwu' name,
'wuli' cla,
'3' num )


select
id,
stuff(
(select ',' + name from  temp00 where id = a.id for xml path(''))
,1,1,'') as names --这个函数
from temp00 a
group by
id


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM