# `PERCENTILE_DISC`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Computes a discrete percentile, returning the first input value whose position in the ordering equals or exceeds the specified fraction.

## Syntax

```sql
percentile_disc(<fraction>) WITHIN GROUP (ORDER BY <sort_expression>)
```

## Arguments

### Required

- `<fraction>`: A `double precision` value between 0 and 1 specifying the percentile to compute.
- `<sort_expression>`: An expression of any sortable type.

## Returns

Returns the same type as the sort expression. Returns NULL if the fraction is NULL.

## Considerations

- This is an ordered-set aggregate function.
- NULL values in the sorted input are ignored.
- Returns an actual value from the input set (no interpolation).
- Use `PERCENTILE_CONT` for continuous percentiles with interpolation.

## Examples

### Calculate Median

Find the median (50th percentile).

```sql
SELECT percentile_disc(0.5) WITHIN GROUP (ORDER BY salary) AS median_salary
FROM employees;
```

### Calculate Quartiles

Find the 25th and 75th percentiles.

```sql
SELECT
    percentile_disc(0.25) WITHIN GROUP (ORDER BY score) AS q1,
    percentile_disc(0.5) WITHIN GROUP (ORDER BY score) AS median,
    percentile_disc(0.75) WITHIN GROUP (ORDER BY score) AS q3
FROM test_results;
```

### Percentile by Group

Calculate percentiles for each group.

```sql
SELECT department,
    percentile_disc(0.9) WITHIN GROUP (ORDER BY response_time) AS p90_response
FROM service_calls
GROUP BY department;
```

## Related Documentation

- [PERCENTILE_CONT](/docs/data/data-cloud-query-guide/references/dc-sql-reference/percentile-cont.md)
- [MODE](/docs/data/data-cloud-query-guide/references/dc-sql-reference/mode.md)
- [Aggregate Functions](/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
