表名是stud
SubjectID StudentName
---------- -------------
1 Mary
1 John
1 Sam
2 Alaina
2 Edward
预期结果:
SubjectID StudentName
---------- -------------
1 Mary, John, Sam
2 Alaina, Edward
使用sql
你可以帮助我们吗答案 0 :(得分:0)
在MySQL中:
SELECT SubjectID, GROUP_CONCAT(StudentName)
FROM stud
GROUP BY SubjectID
答案 1 :(得分:0)
DECLARE @Names VARCHAR(8000)
SELECT @Names = COALESCE(@Names + ', ', '') + StudentName FROM stud
SELECT @Names