@Override
    protected Boolean visitSubqueryExpression(SubqueryExpression node, Void context) {
      /*
       * Column reference can resolve to (a) some subquery's scope, (b) a projection (ORDER BY scope),
       * (c) source scope or (d) outer query scope (effectively a constant).
       * From AggregationAnalyzer's perspective, only case (c) needs verification.
       */
      getReferencesToScope(node, analysis, sourceScope)
          .filter(expression -> !isGroupingKey(expression))
          .findFirst()
          .ifPresent(
              expression -> {
                throw new SemanticException(
                    String.format(
                        "Subquery uses '%s' which must appear in GROUP BY clause", expression));
              });

      return true;
    }
visitor returns true if all expressions are constant with respect to the group.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/AggregationAnalyzer.java