Group
Partitions the rows into groups and applies a pipeline to each of the groups.
group {key_columns} (pipeline)
The partitioning of groups are determined by the key_column
s (first argument).
The most conventional use of group
is with aggregate
:
PRQL
from employees
group {title, country} (
aggregate {
average salary,
ct = count salary
}
)
SQL
SELECT
title,
country,
AVG(salary),
COUNT(*) AS ct
FROM
employees
GROUP BY
title,
country
In concept, a transform in context of a group
does the same transformation to
the group as it would to the table β for example finding the employee who joined
first across the whole table:
To find the employee who joined first in each department, itβs exactly the same
pipeline, but within a group
expression: