Tag archive
Commands grouped around the same concept, pattern, or recurring problem.
Return a value from the first row of a window partition, useful for comparing each row against the group leader.
Use LAST_VALUE with an explicit full-partition frame to compare each row with the final row in its group.
Define a window specification once with a `WINDOW` alias and reference it in multiple `OVER` clauses — avoiding repetition when several window functions share the same partition and ordering.
Use PostgreSQL's `DISTINCT ON (col)` to keep only the first row for each unique value of a column, with `ORDER BY` controlling which row within each group is considered first.