sqlcmd.net validated sql reference

#window

Commands grouped around the same concept, pattern, or recurring problem.

8 commands with this tag Browse related patterns quickly
intermediate windowing MySQL MariaDB SQL Server PostgreSQL SQLite

Bucket Rows Into Equal Groups With NTILE

Use `NTILE(n)` to divide an ordered result set into `n` roughly equal buckets and assign each row a bucket number.

intermediate windowing MySQL MariaDB SQL Server PostgreSQL SQLite

Calculate A Running Count With COUNT OVER

Use COUNT as a window function to number how many rows have appeared up to the current row.

advanced windowing MySQL MariaDB SQL Server PostgreSQL SQLite

Calculate Relative Rank With PERCENT_RANK And CUME_DIST

Use percent-rank window functions to express each row's position within an ordered group.

advanced aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Compute a Median or Arbitrary Percentile

Find the median or any percentile value using `PERCENTILE_CONT` in PostgreSQL, MariaDB, and SQL Server, or a window-function workaround in MySQL and SQLite.

advanced windowing MySQL MariaDB SQL Server PostgreSQL SQLite

Control the Window Frame With ROWS BETWEEN

Use `ROWS BETWEEN` in a window function to aggregate only the rows immediately surrounding each row.

advanced windowing MySQL MariaDB SQL Server PostgreSQL SQLite

Get The Last Value In A Window Partition

Use LAST_VALUE with an explicit full-partition frame to compare each row with the final row in its group.

intermediate windowing MySQL MariaDB SQL Server PostgreSQL SQLite

Name a Window Definition for Reuse

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.

intermediate select MySQL MariaDB SQL Server PostgreSQL SQLite

Select the First Row Per Group With DISTINCT ON

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.