GROUP
Choose the columns your answer is grouped by.
Syntax
GROUP is a clause of LEARN. List the columns in a list of quoted names.
GROUP(["alias.column", "joined_table.column"])Parameters and arguments
listQuoted column names. A column of the FROM table is written with its alias, such as
Required: At least one, when RETURN has a plain column"b.contentType", and a column of a joined table with that table's name, such as"content_types.name"
Examples
Count the navigation links by whether they are published.
Return type and behaviour
LEARN returns one row for each distinct combination of the GROUP columns. Every plain column in RETURN must be one of them, and everything else must be inside an aggregate. A RETURN with only the group columns lists the combinations.
Errors and exceptions
| Error | What happened | How to recover |
|---|---|---|
HTQL-2001 | A column is in RETURN but not in GROUP, and it is not inside an aggregate | Add it to GROUP, or wrap it in COUNT, SUM, MAX, MIN or AVERAGE |
Limitations
- GROUP's names are the tables' columns, not RETURN's names.
- Groups have no fixed order. Use SORT.
- A column left out of GROUP and not inside an aggregate is refused, so no silent extra group appears.
- Not supported:
EXPR("…")as a group key. Group by a column.
Best practices
- Group by the fewest columns that answer your question.
- Sort the groups so the answer reads in a steady order.