cambyzju commented on code in PR #15143: URL: https://github.com/apache/doris/pull/15143#discussion_r1056045507
########## fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java: ########## @@ -989,18 +989,36 @@ private void analyzeAggregation(Analyzer analyzer) throws AnalysisException { * (select min(k1) from table b where a.key=b.k2); * TODO: the a.key should be replaced by a.k1 instead of unknown column 'key' in 'a' */ + + // according to mysql + // having clause should use column name inside group by clause, prior to alias. + // case1: having clause use column name table.v1, because v1 inside group by clause + // select id, sum(v1) v1 from table group by id,v1 having(v1>1); Review Comment: > MySQL's behavior is very strange. according to sql standard, `having` should filter the data after `Aggregate`. So the slot in `having` should always bind on the output of `Aggregate`, in other words, the alias name. Since doris has many different from the behavior of MySQL. Here we should follow the SQL standard instead of MySQL for a more understandable syntax. 1. accord to SQL standard, having clause do not support alias name; 2. Doris always say "compatible with MySQL protocol", lots of SQL keeps Mysql way; 3. Before this pr, we already try to following MySQL way. But the old implement has two problem: - one is, only consider has GROUP BY or NOT, not consider slots inside GROUP BY or not; - the other is, try whole HAVING expr, do consider part slots have alias, part slots do not; So if we want to follow SQL standard, we should better forbid alias name in HAVING clause. But old users will confused, because the behavior changes too large. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org