window
EXCLUDE
Removes the current peer group from the otherwise selected frame. Other choices are CURRENT ROW, TIES (retain current row but remove its other peers), and NO OTHERS. Empty SUM frames yield NULL. Example target: PostgreSQL 17; focused usage form.
Formal Syntax & Structure
sql syntaxsql
SUM(x) OVER (PARTITION BY g ORDER BY x GROUPS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE GROUP)Working Example
Example Snippetsql
WITH t(id,g,x) AS (VALUES (1,'A',10),(2,'A',20),(3,'A',20),(4,'A',40),(5,'B',7)) SELECT id, SUM(x) OVER (PARTITION BY g ORDER BY x GROUPS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE GROUP) AS result FROM t ORDER BY id;