> For the complete documentation index, see [llms.txt](https://upsolver.gitbook.io/content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/aggregate/approx_count_distinct.md).

# APPROX\_COUNT\_DISTINCT

Approximates the number of distinct non-null input values.&#x20;

This function is used as an approximation of [`COUNT(DISTINCT ...)`](/content/reference-1/functions-and-operators/functions/aggregate/count-distinct-....md) in order to improve performance. It should be used when there are relatively few (under one million) rows, and where the total number of distinct values is high.

## Syntax

```sql
APPROX_COUNT_DISTINCT(X)
```

## Arguments

#### `X`

Type: any type

The values to be counted.

## Returns

Type: `bigint`

Returns the approximate number of distinct non-null input values.&#x20;

If all input values are null, zero is returned.

***

## Examples

### Transformation job example

#### SQL

{% code overflow="wrap" %}

```sql
CREATE JOB function_operator_example
    ADD_MISSING_COLUMNS = TRUE
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data
    MAP_COLUMNS_BY_NAME
    SELECT 
        LOWER(ordertype) AS ordertype,
        ROUND(AVG(nettotal), 2) AS avgtotal
    FROM default_glue_catalog.upsolver_samples.orders_raw_data 
    WHERE $commit_time BETWEEN run_start_time() - PARSE_DURATION('1d') 
        AND run_end_time()
    GROUP BY 1
    LIMIT 2;
```

{% endcode %}

#### Query result

| ordertype | avgtotal |
| --------- | -------- |
| pickup    | 1062.14  |
| shipping  | 1061.91  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://upsolver.gitbook.io/content/reference-1/functions-and-operators/functions/aggregate/approx_count_distinct.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
