如果我有一个这样的表:
+------------+
| Id | Value |
+------------+
| 1 | 'A' |
|------------|
| 1 | 'B' |
|------------|
| 2 | 'C' |
+------------+
如何获得这样的结果集:
+------------+
| Id | Value |
+------------+
| 1 | 'AB' |
|------------|
| 2 | 'C' |
+------------+
我知道这在 MySQL 中使用 GROUP_CONCAT 很容易做到,但我需要能够在 MSSQL 2005 中做到这一点
谢谢
(How to use GROUP BY to concatenate strings in SQL Server? 的重复)
最佳答案
要获得干净高效的解决方案,您可以创建 an user defined aggregate function ,甚至还有an example这正是您所需要的。
然后,您可以像任何其他聚合函数一样使用它(使用标准查询计划):
关于sql - SQL Server 中的连接组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/941103/