SQL Window Function Generator
Pick a window function, set PARTITION BY, ORDER BY and an optional frame, and get a ready-to-run SELECT statement. Supports ROW_NUMBER, RANK, DENSE_RANK, NTILE, LAG, LEAD, running totals and moving averages across PostgreSQL, MySQL 8, SQL Server, Oracle, SQLite, BigQuery and Snowflake. Everything runs in your browser — nothing is uploaded.
A unique sequential number per partition. Ties get different numbers, decided by the ORDER BY.
Do more than sql window function generator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Choose the window function you need and your SQL dialect.
- Fill in the table, the target column, and the PARTITION BY / ORDER BY columns.
- Pick a frame if you want a running total or moving window, then copy the generated SQL.
Frequently asked questions
What is the difference between RANK, DENSE_RANK and ROW_NUMBER?
ROW_NUMBER always produces unique consecutive numbers, so tied rows get different numbers in an arbitrary order. RANK gives tied rows the same number and then skips values, producing 1, 2, 2, 4. DENSE_RANK also ties rows together but does not skip, producing 1, 2, 2, 3. Use ROW_NUMBER for deduplication, RANK or DENSE_RANK when ties should be treated equally.
Why does LAST_VALUE return the current row instead of the last one?
When you write an ORDER BY inside OVER() without a frame clause, SQL applies the default frame RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, so the window ends at the current row. Add ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING — the 'Whole partition' frame in this generator — to make LAST_VALUE see the entire partition.
Which databases support SQL window functions?
PostgreSQL has supported them since 8.4, SQL Server since 2005 (frames since 2012), Oracle since 8i, SQLite since 3.25, and BigQuery and Snowflake from the start. MySQL only added them in 8.0, and MariaDB in 10.2 — they are not available in MySQL 5.7. If you want to write and test these queries against any of them from one place, Chat2DB is a free AI SQL client that runs on Windows, macOS and Linux.
