Repository: databendlabs/databend (language: rust)

Issue:
bug: HAVING with subquery can't find the column
### Search before asking

- [X] I had searched in the [issues](https://github.com/databendlabs/databend/issues) and found no similar issues.


### Version

v1.2.682


### What's Wrong?

HAVING with subquery can't find the column

### How to Reproduce?

```sql
root@0.0.0.0:48000/default> create table tt2 (c0 bool, c1 int);
processed in (0.297 sec)

root@0.0.0.0:48000/default> insert into tt2 values(true, 1),(false, 2),(true, 3);
3 rows affected in (0.223 sec)

root@0.0.0.0:48000/default> SELECT string_agg('a') FROM tt2 GROUP BY GROUPING SETS ((c1)) HAVING c0 NOT IN(SELECT true AS czTQb00);
error: APIError: QueryFailed: [1006]Unable to get field named "0". Valid fields: ["5", "1", "3"].
```

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!


Discussion / hints:

Fix patch:
diff --git a/src/query/sql/src/planner/semantic/grouping_check.rs b/src/query/sql/src/planner/semantic/grouping_check.rs
index 21ff5b7bc06a..330c52243103 100644
--- a/src/query/sql/src/planner/semantic/grouping_check.rs
+++ b/src/query/sql/src/planner/semantic/grouping_check.rs
@@ -20,7 +20,6 @@ use crate::binder::Visibility;
 use crate::plans::walk_expr_mut;
 use crate::plans::BoundColumnRef;
 use crate::plans::ScalarExpr;
-use crate::plans::SubqueryExpr;
 use crate::plans::VisitorMut;
 use crate::BindContext;
 
@@ -176,6 +175,11 @@ impl VisitorMut<'_> for GroupingChecker<'_> {
                     return Ok(());
                 }
             }
+            ScalarExpr::SubqueryExpr(q) => {
+                if let Some(c) = q.child_expr.as_mut() {
+                    self.visit(c.as_mut())?;
+                }
+            }
             _ => {}
         }
 
@@ -200,9 +204,4 @@ impl VisitorMut<'_> for GroupingChecker<'_> {
         ))
         .set_span(column.span))
     }
-
-    fn visit_subquery_expr(&mut self, _: &mut SubqueryExpr) -> Result<()> {
-        // TODO(leiysky): check subquery in the future
-        Ok(())
-    }
 }


Test patch:
diff --git a/tests/sqllogictests/suites/query/aggregate.test b/tests/sqllogictests/suites/query/aggregate.test
index 73f5b582ac94..5d61c9c25806 100644
--- a/tests/sqllogictests/suites/query/aggregate.test
+++ b/tests/sqllogictests/suites/query/aggregate.test
@@ -36,6 +36,9 @@ select a, sum(sum) as sum from (select a, sum(a) as sum from t group by a, b) as
 1	2
 2	4
 
+statement error must appear in the GROUP BY clause or be used in an aggregate function
+SELECT max(a) FROM t GROUP BY a HAVING b NOT IN(SELECT 3 AS c);
+
 statement ok
 drop table t