---
title: percentile_disc aggregate function
description: Learn the syntax of the percentile\_disc aggregate function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/percentile_disc
---

# `percentile_disc` aggregate function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 11.3 LTS and above

Returns the value that corresponds to the `percentile` of the provided `sortKey` using a discrete distribution model.

## Syntax

```
percentile_disc ( percentile )
       WITHIN GROUP (ORDER BY sortKey [ASC | DESC] )
```

This function can also be invoked as a [window function](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-window-functions.md) using the `OVER` clause.

## Arguments

* `percentile`: A numeric literal between 0 and 1 or a literal array of numeric literals, each between 0 and 1.
* `sortKey`: A numeric expression over which the percentile is computed.
* `ASC` or `DESC`: Optionally specify whether the percentile is computed using ascending or descending order. The default is `ASC`.

## Returns

DOUBLE if `percentile` is numeric, or an ARRAY of DOUBLE if `percentile` is an ARRAY.

The aggregate function returns the `sortKey` value that matches the `percentile` within the group of `sortKeys`.

## Examples

```sql
-- Return the median, 40%-ile and 10%-ile.
> SELECT percentile_disc(array(0.5, 0.4, 0.1)) WITHIN GROUP (ORDER BY col)
    FROM VALUES (0), (1), (2), (10) AS tab(col);
 [1, 1, 0]

-- Return the interpolated median.
> SELECT percentile_disc(0.50) WITHIN GROUP (ORDER BY col)
    FROM VALUES (0), (6), (6), (7), (9), (10) AS tab(col);
 6
```

## Related

* [`percentile_approx` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/percentile_approx.md)
* [`approx_count_distinct` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/approx_count_distinct.md)
* [`percentile` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/percentile.md)
* [`percentile_cont` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/percentile_cont.md)
* [Window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-window-functions.md)
