mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
fixed groupBy error; close #I7EAY9
This commit is contained in:
parent
fb5488c3fe
commit
e6505f1e27
@ -35,8 +35,23 @@ public class DistinctQueryColumn extends QueryColumn {
|
||||
if (CollectionUtil.isEmpty(queryTables)) {
|
||||
return SqlConsts.EMPTY;
|
||||
}
|
||||
|
||||
String sql = SqlConsts.DISTINCT + StringUtil.join(SqlConsts.DELIMITER, queryColumns, queryColumn ->
|
||||
queryColumn.toSelectSql(queryTables, dialect));
|
||||
|
||||
return sql + WrapperUtil.buildAlias(alias, dialect);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
String toConditionSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
if (CollectionUtil.isEmpty(queryTables)) {
|
||||
return SqlConsts.EMPTY;
|
||||
}
|
||||
|
||||
return SqlConsts.DISTINCT + StringUtil.join(SqlConsts.DELIMITER, queryColumns, queryColumn ->
|
||||
queryColumn.toSelectSql(queryTables, dialect));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -81,6 +81,15 @@ public class FunctionQueryColumn extends QueryColumn implements HasParamsColumn
|
||||
return fnName + WrapperUtil.withAlias(sql, dialect.wrap(alias));
|
||||
}
|
||||
|
||||
@Override
|
||||
String toConditionSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
String sql = column.toSelectSql(queryTables, dialect);
|
||||
if (StringUtil.isBlank(sql)) {
|
||||
return SqlConsts.EMPTY;
|
||||
}
|
||||
return fnName + WrapperUtil.withBracket(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryColumn as(String alias) {
|
||||
SqlUtil.keepColumnSafely(alias);
|
||||
|
||||
@ -506,7 +506,7 @@ public class QueryColumn implements CloneSupport<QueryColumn> {
|
||||
|
||||
|
||||
String toSelectSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
return toConditionSql(queryTables, dialect) + WrapperUtil.withAliasIf(alias, dialect);
|
||||
return toConditionSql(queryTables, dialect) + WrapperUtil.buildAlias(alias, dialect);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -98,9 +98,9 @@ public class QueryTable implements CloneSupport<QueryTable> {
|
||||
public String toSql(IDialect dialect) {
|
||||
String sql;
|
||||
if (StringUtil.isNotBlank(schema)) {
|
||||
sql = dialect.wrap(dialect.getRealSchema(schema)) + "." + dialect.wrap(dialect.getRealTable(name)) + WrapperUtil.withAliasIf(alias, dialect);
|
||||
sql = dialect.wrap(dialect.getRealSchema(schema)) + "." + dialect.wrap(dialect.getRealTable(name)) + WrapperUtil.buildAlias(alias, dialect);
|
||||
} else {
|
||||
sql = dialect.wrap(dialect.getRealTable(name)) + WrapperUtil.withAliasIf(alias, dialect);
|
||||
sql = dialect.wrap(dialect.getRealTable(name)) + WrapperUtil.buildAlias(alias, dialect);
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ class WrapperUtil {
|
||||
return SqlConsts.BRACKET_LEFT + sql + SqlConsts.BRACKET_RIGHT + SqlConsts.AS + alias;
|
||||
}
|
||||
|
||||
static String withAliasIf(String alias, IDialect dialect) {
|
||||
static String buildAlias(String alias, IDialect dialect) {
|
||||
return StringUtil.isBlank(alias) ? SqlConsts.EMPTY : SqlConsts.AS + dialect.wrap(alias);
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,6 +263,15 @@ public class AccountSqlTester {
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroup_I7EAY9() {
|
||||
QueryWrapper query = QueryWrapper.create()
|
||||
.from(ACCOUNT).as("a")
|
||||
.from(ACCOUNT01).as("b")
|
||||
.groupBy(year(ACCOUNT.BIRTHDAY));
|
||||
System.out.println(query.toSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHavingSql() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user