Skip to main content

Aggregate Functions

Aggregate functions are essential tools in SQL that allow you to perform calculations on a set of values and return a single result.

These functions help you extract and summarize data from databases to gain valuable insights.

Function NameWhat It Does
COUNTCounts the number of rows that meet certain criteria
COUNT_IFCounts rows meeting a specified condition
COUNT_DISTINCTCounts the number of distinct values in a column
APPROX_COUNT_DISTINCTEstimates the number of distinct values with HyperLogLog
SUMAdds up the values of a specific column
AVGCalculates the average value of a specific column
AVG_IFCalculates the average for rows meeting a condition
MINFinds the smallest value in a specific column
MIN_IFFinds the minimum value for rows meeting a condition
MAXFinds the largest value in a specific column
MAX_IFFinds the maximum value for rows meeting a condition
ANYChecks if any row meets the specified condition
ARG_MAXFinds the arg value for the maximum val value
ARG_MINFinds the arg value for the minimum val value
COVAR_POPReturns the population covariance of a set of number pairs
COVAR_SAMPReturns the sample covariance of a set of number pairs
STDDEV_POPCalculates the population standard deviation of a column
STDDEV_SAMPCalculates the sample standard deviation of a column
MEDIANCalculates the median value of a specific column
QUANTILECalculates the quantile for a specific column
RETENTIONCalculates retention for a set of events
WINDOW_FUNNELAnalyzes user behavior in a time-ordered sequence of events
LISTConverts all the values of a column to an Array