# `AVG`

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

Computes the average (arithmetic mean) of all input values.

## Syntax

```sql
avg(<expression>)
```

## Arguments

### Required

- `<expression>`: An expression of any numerical type.

## Returns

- `numeric` with a scale of 6 for integer-type arguments and numeric arguments with a scale less than 6.
- `double precision` for floating-point arguments.
- Otherwise, returns the same as argument the type.

Returns NULL if no rows are selected.

## Considerations

- NULL values are ignored in the calculation.
- Returns NULL when applied to an empty set.
- Use `COALESCE` to substitute a default value for NULL results.

## Examples

### Calculate Average

Get the average price of products.

```sql
SELECT avg(price) AS average_price
FROM products;
```

### Average by Group

Calculate the average salary by department.

```sql
SELECT department, avg(salary) AS avg_salary
FROM employees
GROUP BY department;
```

### Handle Empty Results

Use COALESCE to handle NULL results.

```sql
SELECT coalesce(avg(quantity), 0) AS avg_quantity
FROM orders
WHERE order_date > '2024-01-01';
```

## Related Documentation

- [SUM](/docs/data/data-cloud-query-guide/references/dc-sql-reference/sum.md)
- [COUNT](/docs/data/data-cloud-query-guide/references/dc-sql-reference/count.md)
- [Aggregate Functions](/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
