Concat groups in SQL Server(SQL Server 中的连接组)
问题描述
如果我有一张这样的桌子:
If I have a table like this:
+------------+
| Id | Value |
+------------+
| 1 | 'A' |
|------------|
| 1 | 'B' |
|------------|
| 2 | 'C' |
+------------+
我怎样才能得到这样的结果集:
How can I get a resultset like this:
+------------+
| Id | Value |
+------------+
| 1 | 'AB' |
|------------|
| 2 | 'C' |
+------------+
我知道这在 MySQL 中使用 GROUP_CONCAT 很容易做到,但我需要能够在 MSSQL 2005 中做到这一点
I know this is really easy to do in MySQL using GROUP_CONCAT, but I need to be able to do it in MSSQL 2005
谢谢
(重复 如何使用 GROUP BY在 SQL Server 中连接字符串?)
推荐答案
要获得干净高效的解决方案,您可以创建 一个用户定义的聚合函数,甚至还有一个例子 可以满足您的需求.
然后,您可以像使用任何其他聚合函数一样使用它(使用标准查询计划):
For a clean and efficient solution you can create an user defined aggregate function, there is even an example that does just what you need.
You can then use it like any other aggregate function (with a standard query plan):
这篇关于SQL Server 中的连接组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server 中的连接组
基础教程推荐
- 什么是 orradiag_<user>文件夹? 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 在多列上分布任意行 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
