diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index 86771edd5c..c8bc8ddf43 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -1341,9 +1341,13 @@ public class SelectStmt extends QueryStmt { countAllMap = ExprSubstitutionMap.compose(multiDistinctAggMap, countAllMap, analyzer); List substitutedAggs = Expr.substituteList(aggExprs, countAllMap, analyzer, false); - // the resultExprs must substitute in the same way as aggExprs - // then resultExprs can be substitute correctly using combinedSmap + // the resultExprs and havingClause must substitute in the same way as aggExprs + // then resultExprs and havingClause can be substitute correctly using combinedSmap resultExprs = Expr.substituteList(resultExprs, countAllMap, analyzer, false); + if (havingClauseAfterAnaylzed != null) { + havingClauseAfterAnaylzed = + havingClauseAfterAnaylzed.substitute(countAllMap, analyzer, false); + } aggExprs.clear(); TreeNode.collect(substitutedAggs, Expr.isAggregatePredicate(), aggExprs); diff --git a/regression-test/data/correctness_p0/test_group_having_alias.out b/regression-test/data/correctness_p0/test_group_having_alias.out index cc442bedcc..727040875a 100644 --- a/regression-test/data/correctness_p0/test_group_having_alias.out +++ b/regression-test/data/correctness_p0/test_group_having_alias.out @@ -36,6 +36,9 @@ -- !case5 -- 2 3 +-- !case_cir2273 -- +2.5 + -- !case6 -- 202245 202245 diff --git a/regression-test/suites/correctness_p0/test_group_having_alias.groovy b/regression-test/suites/correctness_p0/test_group_having_alias.groovy index fc5b09e8d1..fc5e112d1d 100644 --- a/regression-test/suites/correctness_p0/test_group_having_alias.groovy +++ b/regression-test/suites/correctness_p0/test_group_having_alias.groovy @@ -128,6 +128,7 @@ qt_case3 """ SELECT id, v1-2 as v, sum(v2) v2 FROM test_having_alias_tb GROUP BY id,v having(v>0 AND sum(v2)>1) ORDER BY id,v; """ qt_case4 """ SELECT id, v1-2 as v, sum(v2) vsum FROM test_having_alias_tb GROUP BY id,v having(v>0 AND vsum>1) ORDER BY id,v; """ qt_case5 """ SELECT id, max(v1) v1 FROM test_having_alias_tb GROUP BY 1 having count(distinct v1)>1 ORDER BY id; """ + qt_case_cir2273 """ select sum( id * 0.5 ) val from test_having_alias_tb having val > 0; """ sql """set enable_nereids_planner=true""" sql """set enable_fallback_to_original_planner=false"""