You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The GROUP BY clause is used to group rows together with specified group key. In standard SQL, the group key can only be column, but in databend we allow the group key to be scalar expression, e.g. a + 1, a + b.
With GROUP BY, we cannot reference any non-grouped columns in SELECT clause directly(select b from t group by a is not allowed), since after grouping the non-grouped columns are reduced with aggregate functions and cannot appear in result set.
Aggregate functions are the functions that takes groups as input, and produce a single accumulated value as result. Aggregated functions can only work with GROUP BY. If there is a query with aggregate function(e.g. select count(*) from t) but no group key is specified, it will be treated as an aggregate query has only one group which consists of all the input rows.
If we want to filter the aggregated result, a HAVING clause can be utilized with. You can reference aggregate functions and group keys in HAVING clause(which is pretty similar with WHERE clause).
Here's an example of aggregate:
SELECT a, sum(b + c) +1FROM t GROUP BY a, b +1HAVING b +1>1;
a is one of the group keys, so it could appears in the result. Although b and c are not group keys, they can be referenced by an aggregate function sum.
b + 1 is one of the group keys, so we can use it in HAVING clause. But if we replace the b + 1 > 1 with b > 0, then the query won't work.
The text was updated successfully, but these errors were encountered:
Implement aggregate operator in new planner.
The
GROUP BY
clause is used to group rows together with specified group key. In standard SQL, the group key can only be column, but in databend we allow the group key to be scalar expression, e.g.a + 1
,a + b
.With
GROUP BY
, we cannot reference any non-grouped columns inSELECT
clause directly(select b from t group by a
is not allowed), since after grouping the non-grouped columns are reduced with aggregate functions and cannot appear in result set.Aggregate functions are the functions that takes groups as input, and produce a single accumulated value as result. Aggregated functions can only work with
GROUP BY
. If there is a query with aggregate function(e.g.select count(*) from t
) but no group key is specified, it will be treated as an aggregate query has only one group which consists of all the input rows.If we want to filter the aggregated result, a
HAVING
clause can be utilized with. You can reference aggregate functions and group keys inHAVING
clause(which is pretty similar withWHERE
clause).Here's an example of aggregate:
a
is one of the group keys, so it could appears in the result. Althoughb
andc
are not group keys, they can be referenced by an aggregate functionsum
.b + 1
is one of the group keys, so we can use it inHAVING
clause. But if we replace theb + 1 > 1
withb > 0
, then the query won't work.The text was updated successfully, but these errors were encountered: