public class GroupConcat extends ColumnFunctionDecorator implements TableFunction
GROUP_CONCAT 是 MySQL 特有的字符串聚合函数,用于将同一分组内的多行值拼接成一个字符串。 支持 DISTINCT、ORDER BY、SEPARATOR 等子句,语法结构如下:
GROUP_CONCAT(
[DISTINCT] expr
[ORDER BY col1 ASC, col2 DESC]
[SEPARATOR 'separator']
)
典型示例:
GROUP_CONCAT(users.name) GROUP_CONCAT(users.name SEPARATOR '; ') GROUP_CONCAT(DISTINCT users.name ORDER BY users.age ASC, users.id DESC SEPARATOR '; ')
对于复杂构建,通过 GroupConcat.GroupConcatOptions 对 DISTINCT、ORDER BY、SEPARATOR 等子句进行建模,
并在 render(RenderContext) 中生成最终 SQL。
| 限定符和类型 | 类和说明 |
|---|---|
static class |
GroupConcat.GroupConcatOptions
group_concat 子句配置对象。
|
parameterBinder, valuedelegateFunction| 构造器和说明 |
|---|
GroupConcat(FieldFn<T,F> fn)
构造一个最简单的 GROUP_CONCAT(expr)
|
GroupConcat(FieldFn<T,F> fn,
String separator)
构造 GROUP_CONCAT(expr SEPARATOR 'xxx')
|
GroupConcat(GroupConcat.GroupConcatOptions options)
使用完整的 GROUP_CONCAT 配置对象
|
| 限定符和类型 | 方法和说明 |
|---|---|
String |
render(RenderContext context)
根据给定的渲染上下文生成 SQL 字符串。
|
appendArithmeticSql, getTableAlias, originColumn, parameterBinderadd, add, add, add, divide, divide, divide, divide, getAliasTableMap, getArithmetic, getDataSourceName, getDelegateFunction, multiply, multiply, multiply, multiply, setAliasTableMap, setArithmetic, setDataSourceName, subtract, subtract, subtract, subtractclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitoriginColumnparameterBindersetTableAliaspublic GroupConcat(FieldFn<T,F> fn)
public GroupConcat(FieldFn<T,F> fn, String separator)
public GroupConcat(GroupConcat.GroupConcatOptions options)
public String render(RenderContext context)
SqlRenderablerender 在接口中 SqlRenderablecontext - 渲染上下文,包含方言、别名、版本等信息Copyright © 2024–2026 Dynamic-SQL. All rights reserved.