Available in versions: Dev (3.21) | Latest (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

MODE (unordered)

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The MODE() aggregate function calculates the statistical mode of all input values, i.e. the value that appears most in the data set. Unlike the MODE (ordered) variant of this function, this unordered variant does not allow for chosing among tied modes.

SELECT mode(BOOK.LANGUAGE_ID)
FROM BOOK
create.select(mode(BOOK.LANGUAGE_ID))
      .from(BOOK)

Producing:

+------+
| mode |
+------+
|    1 |
+------+

See also MODE (ordered).

Dialect support

This example using jOOQ:

mode(BOOK.LANGUAGE_ID)

Translates to the following dialect specific expressions:

Aurora Postgres, DuckDB, H2, Postgres

mode() WITHIN GROUP (ORDER BY BOOK.LANGUAGE_ID)

Databricks, Snowflake

mode(BOOK.LANGUAGE_ID)

Oracle

stats_mode(BOOK.LANGUAGE_ID)

ASE, Access, Aurora MySQL, BigQuery, ClickHouse, CockroachDB, DB2, Exasol, Firebird, HSQLDB, Hana, Informix, MariaDB, MemSQL, MySQL, Redshift, SQLDataWarehouse, SQLServer, SQLite, Spanner, Sybase, Teradata, Trino, Vertica, YugabyteDB

/* UNSUPPORTED */
Generated with jOOQ 3.21. Support in older jOOQ versions may differ. Translate your own SQL on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo