Window Functions and CTEs Now Available in StackQL
· 2 min read
Window functions and Common Table Expressions (CTEs) are now generally available in StackQL. These features work with both the embedded SQLite backend and PostgreSQL backend.
Window Functions
Window functions allow you to perform calculations across sets of rows related to the current row. Supported functions include:
- Ranking:
ROW_NUMBER(),RANK(),DENSE_RANK(),NTILE() - Offset:
LAG(),LEAD(),FIRST_VALUE(),LAST_VALUE(),NTH_VALUE() - Distribution:
PERCENT_RANK(),CUME_DIST() - Aggregates as window functions:
SUM(),COUNT(),AVG(), etc. withOVERclause
Example: Ranking Contributors
SELECT
login,
contributions,
DENSE_RANK() OVER (ORDER BY contributions DESC) as rank
FROM github.repos.contributors
WHERE owner = 'stackql' AND repo = 'stackql';