增加一张学生表,列分别为(stuID,sName,hobby),stuID代表学生编号,sName代表学生姓名,hobby学生的爱好:
create table student
( stuID int,sName varchar(16),hobby varchar(16))
SELECT sName,
( SELECT hobby+','
FROM student
WHERE sName=A.sName
FOR XML PATH('') ) AS 'hobby'
FROM student AGROUP BY sName
结果