GROUPS is one of the three frame units (ROWS, RANGE, GROUPS) available in window functions. When you declare a frame with GROUPS, the database groups adjacent rows with equal ORDER BY values into "peer groups" and then applies the boundary logic to those groups rather than to single rows. This is useful when you want calculations like running totals, moving averages, or ranking statistics to respect ties in the ordering column.Key points:- Requires an ORDER BY clause inside the window definition.- Frame boundaries may use UNBOUNDED PRECEDING/FOLLOWING, CURRENT ROW, or a signed integer followed by PRECEDING/FOLLOWING.- The integer boundaries count peer groups, not physical rows.- If two rows share the same ORDER BY values they belong to the same peer group and are always either wholly inside or outside the frame.- Supported in the SQL:2012 standard and later, but not all engines implement it yet.
start_boundary
(keyword (UNBOUNDED, CURRENT) or integer) - Defines the lower edge of the frame.end_boundary
(keyword (UNBOUNDED, CURRENT) or integer) - Defines the upper edge of the frame.WINDOW, OVER, ROWS, RANGE, PARTITION BY, ORDER BY, Window Functions
SQL:2012
GROUPS tells the database to measure the window frame in peer groups defined by equal ORDER BY values instead of individual rows.
No. GROUP BY aggregates the entire result set once, whereas GROUPS only affects how a window frame is sliced for each row.
At the time of writing: PostgreSQL 14+, Oracle 12c+, and Google BigQuery. Engines like MySQL, SQLite, and most SQL Server versions do not yet support it.
A single window definition can only use one frame unit. Choose either ROWS, RANGE, or GROUPS for that window.