GROUP BY keyword
Groups aggregation calculations by one or several keys. In QuestDB, this clause is optional.
#
Syntaxnote
QuestDB groups aggregation results implicitly and does not require the GROUP BY keyword. It is only supported for convenience. Using the GROUP BY clause explicitly will return the same results as if the clause was omitted.
#
ExamplesThe below queries perform aggregations on a single key. Using GROUP BY
explicitly or implicitly yields the same results:
Single key aggregation, explicit GROUP BY
Single key aggregation, implicit GROUP BY
The below queries perform aggregations on multiple keys. Using GROUP BY
explicitly or implicitly yields the same results:
Multiple key aggregation, explicit GROUP BY
Multiple key aggregation, implicit GROUP BY
When used explicitly, the list of keys in the GROUP BY
clause must match the
list of keys in the SELECT
clause, otherwise an error will be returned:
Error - Column b is missing in the GROUP BY clause
Error - Column b is missing in the SELECT clause
Success - Columns match