AVG
Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
Computes the average (arithmetic mean) of all input values.
Syntax
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.
1SELECT avg(price) AS average_price
2FROM products;
Average by Group
Calculate the average salary by department.
1SELECT department, avg(salary) AS avg_salary
2FROM employees
3GROUP BY department;
Handle Empty Results
Use COALESCE to handle NULL results.
1SELECT COALESCE(avg(quantity), 0) AS avg_quantity
2FROM orders
3WHERE order_date > '2024-01-01';
Related Documentation