在 CockroachDB 的 GROUP BY 子句的 return 集中连接字符串
Concatenating strings in the return set of a GROUP BY clause in CockroachDB
CockroachDB 是否支持类似 MySQL 的 group_concat()
函数,让我在 GROUP BY 组中连接列的值?
例如,如果我想将一个订单中的所有项目描述连接成一个字符串。给定以下示例数据:
Order_ID | Item_ID | Description
---------|---------|------------
1 | 1001 | Apple
1 | 1002 | Banana
2 | 1001 | Apple
2 | 1003 | Orange
然后我想 return:
Order_ID | Items
---------|--------------
1 | AppleBanana
2 | AppleOrange
您可以在要连接在一起的列上使用 concat_agg
函数。
使用上面的例子,你会 运行:
SELECT concat_agg(Description)
FROM Orders
GROUP BY Order_ID
ORDER BY Order_ID;
这将生成一个输出,其中包含所有连接的描述,并按订单 ID 分组。
CockroachDB 是否支持类似 MySQL 的 group_concat()
函数,让我在 GROUP BY 组中连接列的值?
例如,如果我想将一个订单中的所有项目描述连接成一个字符串。给定以下示例数据:
Order_ID | Item_ID | Description
---------|---------|------------
1 | 1001 | Apple
1 | 1002 | Banana
2 | 1001 | Apple
2 | 1003 | Orange
然后我想 return:
Order_ID | Items
---------|--------------
1 | AppleBanana
2 | AppleOrange
您可以在要连接在一起的列上使用 concat_agg
函数。
使用上面的例子,你会 运行:
SELECT concat_agg(Description)
FROM Orders
GROUP BY Order_ID
ORDER BY Order_ID;
这将生成一个输出,其中包含所有连接的描述,并按订单 ID 分组。