Basic Aggregates
COUNT
Count rows or non-NULL values:SUM
Sum numeric values:AVG
Calculate average:MIN / MAX
Find minimum and maximum values:Statistical Aggregates
STDDEV / STDDEV_SAMP
Sample standard deviation:STDDEV_POP
Population standard deviation:VAR_SAMP
Sample variance:VAR_POP
Population variance:COVAR_SAMP
Sample covariance:COVAR_POP
Population covariance:CORR
Correlation coefficient:Positional Aggregates
FIRST
Return first value:LAST
Return last value:FIRST_NOT_NULL
Return first non-NULL value:LAST_NOT_NULL
Return last non-NULL value:String Aggregates
STRING_AGG
Concatenate strings:Percentile Aggregates
PERCENTILE_APPROX
Approximate percentile (faster):GROUP BY
Group rows for aggregation:Single Column
Multiple Columns
HAVING Clause
Filter grouped results:Time-Series Aggregations
SAMPLE BY Aggregation
Aggregate by time intervals:Rolling Aggregations
Combine with WINDOW JOIN for rolling calculations:Advanced Aggregation Patterns
Conditional Aggregation
Use CASE for conditional aggregation:Multiple Aggregation Levels
Nested aggregations:Pivot-Style Aggregation
Create columns from row values:Performance Tips
Vectorized Aggregation
QuestDB automatically uses SIMD vectorization for aggregates:Indexed GROUP BY
Use SYMBOL columns for faster GROUP BY:Parallel Aggregation
QuestDB can parallelize aggregations across CPU cores automatically.Filter Before Aggregation
Reduce data volume before aggregating:NULL Handling
Aggregate functions handle NULL values:count()- counts all rowscount(column)- counts non-NULL valuessum(),avg(),min(),max()- ignore NULL valuesfirst(),last()- may return NULLfirst_not_null(),last_not_null()- skip NULL values
Examples
Daily Trading Summary
Market Statistics
Hourly Volume Profile
Next Steps
- Window Functions - Use analytical window functions
- Time-Series Functions - Learn SAMPLE BY and LATEST ON
- JOIN Operations - Combine data from multiple tables