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