【发布时间】:2017-10-03 16:35:13
【问题描述】:
MS-SQL,..
假设我有一个名为 dbo.students 的表,其中包含如下字段
SubjectID StudentfName StudentsName
---------- ------------- ------------
1 Mary Abc
1 John Defs
1 Sam Ghix
2 Alaina Jklxx
2 Edward Mnoqwww
我期望的结果是这样的:
SubjectID StudentName
---------- -------------
1 Mary Abc, John Defs, Sam Ghix
2 Alaina Jklxx, Edward Mnoqwww
我知道如何将 StudentfName 和 StudentsName 组合为 StudentName,但我想使用 SubjectID 中的唯一值将所有名称组合在一行中?
【问题讨论】:
-
Aaron Bertrand 解释了SQL Server Gruped Concatenation 中的所有选项。我使用 SQLCLR 聚合,因为它是最快且最容易使用的。
标签: sql-server string-aggregation