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 Name | What It Does |
---|---|
COUNT | Counts the number of rows that meet certain criteria |
COUNT_IF | Counts rows meeting a specified condition |
COUNT_DISTINCT | Counts the number of distinct values in a column |
APPROX_COUNT_DISTINCT | Estimates the number of distinct values with HyperLogLog |
SUM | Adds up the values of a specific column |
AVG | Calculates the average value of a specific column |
AVG_IF | Calculates the average for rows meeting a condition |
MIN | Finds the smallest value in a specific column |
MIN_IF | Finds the minimum value for rows meeting a condition |
MAX | Finds the largest value in a specific column |
MAX_IF | Finds the maximum value for rows meeting a condition |
ANY | Checks if any row meets the specified condition |
ARG_MAX | Finds the arg value for the maximum val value |
ARG_MIN | Finds the arg value for the minimum val value |
COVAR_POP | Returns the population covariance of a set of number pairs |
COVAR_SAMP | Returns the sample covariance of a set of number pairs |
STDDEV_POP | Calculates the population standard deviation of a column |
STDDEV_SAMP | Calculates the sample standard deviation of a column |
MEDIAN | Calculates the median value of a specific column |
QUANTILE | Calculates the quantile for a specific column |
RETENTION | Calculates retention for a set of events |
WINDOW_FUNNEL | Analyzes user behavior in a time-ordered sequence of events |
LIST | Converts all the values of a column to an Array |