Skip to main content
Version: 1.0.0

Grouping

group by creates one result for each distinct field value:

select {region, revenue: sum(amount)}
from 'orders.json'
group by region

Given orders from EU and US, the result contains one summary object for each region.

Multiple group fields

Use commas to form groups from a combination of values:

group by region, channel

This creates separate groups such as EU + web and EU + partner. Groups keep their first-seen input order. Missing and explicit null keys belong to the same group.

Filtering before grouping

where filters individual rows first:

select {region, revenue: sum(amount)}
from 'orders.json'
where status = 'paid'
group by region

Only paid orders contribute to the totals.

Filtering groups

having filters the completed summaries:

select {region, revenue: sum(amount)}
from 'orders.json'
group by region
having revenue >= 100

Only regions with at least 100 in revenue remain.

Groups keep first-seen source order. A projected field that is neither grouped nor aggregated comes from the first row in its group.