SELECT name,
(SELECT value+',' FROM test
WHERE name=A.name
FOR XML PATH('')) AS StuList
FROM test A
GROUP BY name
3. 最终效果
SELECT B.sName,LEFT(StuList,LEN(StuList)-1) as hobby FROM (
SELECT sName,
(SELECT hobby+',' FROM student
WHERE sName=A.sName
FOR XML PATH('')) AS StuList
FROM student A
GROUP BY sName
) B