> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.firebolt.io/feedback

```json
{
  "path": "/reference-sql/functions-reference/aggregation/variance-samp",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

> Reference material for VAR_SAMP

# VAR_SAMP

Computes the sample variance of all non-`NULL` numeric values produced by an expression. The sample variance measures the average of the squared differences from the sample mean, indicating how spread out the values are within a sample.
For information about the population variance, which measures how spread out the values are within the full population, see [VAR\_POP](/reference-sql/functions-reference/aggregation/variance-pop).

**Alias**: `VARIANCE`

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ VARIANCE | VAR_SAMP }(<expression>) [FILTER ([WHERE] <condition>)]
```

## Parameters

| Parameter      | Description                                                                        | Supported input types      |
| :------------- | :--------------------------------------------------------------------------------- | :------------------------- |
| `<expression>` | An expression producing numeric values for which to calculate the sample variance. | `REAL`, `DOUBLE PRECISION` |
| `<condition>`  | An optional boolean expression to filter rows used in aggregation                  | `BOOL`                     |

## Return Type

`VAR_SAMP` returns a result of type `DOUBLE PRECISION`.

### Special cases

* If there is at most one non-`NULL` input value, the result is `NULL`.
* If the input contains an `Inf` or `NaN` value, the result will be `NaN`.

## Example

The following code creates an `exams` table with a `grade` column of type `DOUBLE PRECISION`, and inserts five grade values into it:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
CREATE TABLE exams (grade DOUBLE PRECISION);
INSERT INTO exams VALUES (4.0), (3.7), (3.3), (2.7), (2.7);
```

The following code calculates the sample variance of the grade values from the `exams` table, rounds the result to three decimal places, and returns it as `variance`:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT ROUND(VAR_SAMP(grade), 3) as variance from exams;
```

**Returns**
The previous code returns the following result:

| variance (DOUBLE PRECISION) |
| :-------------------------- |
| 0.342                       |
