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