SQL Window Functions
Window/analytical functions — ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, NTILE. This category documents 30 SQL window functions entries, and each page gives you the full syntax, the parameter list, the return value, and a runnable example tested against MySQL, PostgreSQL, SQL Server, and SQLite. The entries are: ROW_NUMBER(), RANK(), DENSE_RANK(), LAG(), LEAD(), NTILE(), SUM() OVER, COUNT() OVER, AVG() OVER, FIRST_VALUE(), LAST_VALUE(), NTH_VALUE(), PERCENT_RANK(), CUME_DIST(), PERCENTILE_CONT(), PERCENTILE_DISC(), GROUPS Frame, EXCLUDE Clause, Moving Average (Window), Running Total (Cumulative), QUALIFY Clause (Snowflake), RANGE BETWEEN (Date Range), PERCENTILE_CONT Window Usage, Window Frame: ROWS vs RANGE vs GROUPS, Window Frame EXCLUDE, COUNT(DISTINCT) OVER (Window), LEAD/LAG with Default, RATIO_TO_REPORT() over PARTITION, Oracle PARTITION BY (Window Clause), SQL LAG/LEAD with IGNORE NULLS. Not sure where to start? ROW_NUMBER() and RANK() are the most commonly used entries in this category. You can also search across every category from the search page, browse the complete A–Z index, or try any of these statements live in the SQL playground.