avg
Calculate the arithmetic mean — average order value, session duration, latency.
Signature
avg(column): Float64Returns
Float64
What it does
Returns the arithmetic mean (sum / count) of non-NULL values in a numeric column. Always returns Float64. Use avgIf(col, cond) for conditional averages in a single pass.
avg() is the standard mean aggregate for ClickHouse analytics: average order value, average session length, average response time (though quantile() is usually better for latency). It is implemented as sum(col) / count(col) internally. For weighted averages use sumProduct(col, weight) / sum(weight) with raw SQL.
Notes
- avg() always returns Float64, even for integer inputs.
- For latency/performance metrics, use quantile(0.5)(latency) instead — the median is more robust than the mean.
- avgWeighted(value, weight) computes a weighted mean in a single expression.
Example SQL
avg in ClickHouse SQL
TypeScript with hypequery
Use avg in a typed TypeScript query
hypequery gives you a type-safe query builder for ClickHouse. The generated schema maps your ClickHouse columns to TypeScript types, and raw SQL expressions let you incorporate functions like avg when you need them inside a builder query.
Common questions
What developers search for with avg
Average order value ClickHouse TypeScript
avg(order_value) gives AOV per day or cohort. In hypequery, chain .groupBy() on the date bucket and .orderBy() for a clean time series.
FAQ
Frequently asked questions about avg
When should I use quantile() instead of avg()?
For latency, load time, or any metric with outliers, use quantile(0.5)(col) for the median. avg() is skewed by outliers and rarely reflects typical user experience.
Related guides
Next step
Use avg in a type-safe TypeScript query
hypequery generates TypeScript types from your ClickHouse schema. Use avg alongside the builder, and reach for raw SQL expressions when the function is not exposed as a dedicated helper.