All versions: 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | Development versions: 3.14 | Unsupported versions: 3.7 | 3.6 | 3.5 | 3.4 | 3.3

The WINDOW clause

Available in ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The SQL:2003 standard supports a WINDOW clause that allows for specifying WINDOW frames for reuse in SELECT clauses and ORDER BY clauses. It is natively supported by:

  • H2
  • MySQL
  • PostgreSQL
  • SQLite
  • Sybase SQL Anywhere

  LAG(first_name, 1) OVER w "prev",
  LEAD(first_name, 1) OVER w "next"
FROM author
WINDOW w AS (ORDER first_name)
ORDER BY first_name DESC
WindowDefinition w = name("w").as(
   lag(AUTHOR.FIRST_NAME, 1).over(w).as("prev"),
   lead(AUTHOR.FIRST_NAME, 1).over(w).as("next"))

Note that in order to create such a window definition, we need to first create a name reference using

Even if only PostgreSQL and Sybase SQL Anywhere natively support this great feature, jOOQ can emulate it by expanding any org.jooq.WindowDefinition and org.jooq.WindowSpecification types that you pass to the window() method - if the database supports window functions at all.

Some more information about window functions and the WINDOW clause can be found on our blog:

The jOOQ Logo