Available in versions: Dev (3.21)
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.
APPROX_PERCENTILE_DISC
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The APPROX_PERCENTILE_DISC() approximative aggregate function is an ordered set function that calculates a given discrete percentile of all input values using a faster, approximative algorithm than the exact PERCENTILE_DISC version. If a RDBMS supports the exact version, but not the approximative one, the exact version is used.
SELECT approx_percentile_disc(0.00) WITHIN GROUP (ORDER BY ID), approx_percentile_disc(0.25) WITHIN GROUP (ORDER BY ID), approx_percentile_disc(0.50) WITHIN GROUP (ORDER BY ID), approx_percentile_disc(0.75) WITHIN GROUP (ORDER BY ID), approx_percentile_disc(1.00) WITHIN GROUP (ORDER BY ID) FROM BOOK
create.select(
approxPercentileDisc(0.00).withinGroupOrderBy(BOOK.ID),
approxPercentileDisc(0.25).withinGroupOrderBy(BOOK.ID),
approxPercentileDisc(0.50).withinGroupOrderBy(BOOK.ID),
approxPercentileDisc(0.75).withinGroupOrderBy(BOOK.ID),
approxPercentileDisc(1.00).withinGroupOrderBy(BOOK.ID))
.from(BOOK)
Producing:
+------+------+------+------+------+ | 0.00 | 0.25 | 0.50 | 0.75 | 1.00 | +------+------+------+------+------+ | 1 | 1 | 2 | 3 | 4 | +------+------+------+------+------+
Dialect support
This example using jOOQ:
approxPercentileDisc(0.00).withinGroupOrderBy(BOOK.ID)
Translates to the following dialect specific expressions:
Aurora Postgres, Postgres, YugabyteDB
percentile_disc(CAST(0E0 AS double precision)) WITHIN GROUP (ORDER BY BOOK.ID)
BigQuery
approx_quantiles(BOOK.ID, 100)[OFFSET(CAST((0E0 * 100) AS int64))]
ClickHouse
quantileTDigest(0E0)(BOOK.ID)
Databricks, MemSQL, Snowflake, Trino
approx_percentile(0E0, BOOK.ID)
DB2, H2
percentile_disc(CAST(0E0 AS double)) WITHIN GROUP (ORDER BY BOOK.ID)
DuckDB
approx_quantile(0E0, BOOK.ID)
Exasol, MariaDB, Teradata
percentile_disc(0E0) WITHIN GROUP (ORDER BY BOOK.ID)
Oracle
approx_percentile(0E0) WITHIN GROUP (ORDER BY BOOK.ID)
Redshift
APPROXIMATE percentile_disc(0E0) WITHIN GROUP (ORDER BY BOOK.ID)
SQLDataWarehouse, SQLServer
approx_percentile_disc(CAST(0E0 AS float)) WITHIN GROUP (ORDER BY BOOK.ID)
ASE, Access, Aurora MySQL, CockroachDB, Firebird, HSQLDB, Hana, Informix, MySQL, SQLite, Spanner, Sybase, Vertica
/* 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!