> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Functions

> Reference of LayersQL aggregation functions — SUM, COUNT, AVG, percentiles, and rates — usable in the SHOW clause to compute metrics over grouped rows.

### SUM(expr)

* Adds values of expr across rows in each group.
* Example:
  ```sql theme={null}
  FROM products
  SHOW SUM(total_sales)
  GROUP BY product_id
  SINCE -7d
  ```

### COUNT(expr)

* Counts non-null occurrences of expr within each group.
* Example:
  ```sql theme={null}
  FROM products
  SHOW COUNT(quantity_purchased)
  GROUP BY product_id
  SINCE -7d
  ```

### COUNT(\*)

* Counts all rows in each group.
* Example:
  ```sql theme={null}
  FROM products
  SHOW COUNT(*)
  GROUP BY geo_country
  SINCE this_month
  ```

### AVG(expr)

* Average of expr per group.
* Example:
  ```sql theme={null}
  FROM products
  SHOW AVG(total_sales)
  GROUP BY product_id
  SINCE past_30_days
  ```

### MIN(expr)

* Minimum value of expr per group.
* Example:
  ```sql theme={null}
  FROM products
  SHOW MIN(total_sales)
  GROUP BY product_id
  SINCE past_90_days
  ```

### MAX(expr)

* Maximum value of expr per group.
* Example:
  ```sql theme={null}
  FROM products
  SHOW MAX(total_sales)
  GROUP BY product_id
  SINCE past_90_days
  ```

### COUNT\_DISTINCT(expr)

* Counts distinct non-null values of expr per group.
* Commonly used for session-based metrics.
* Example:
  ```sql theme={null}
  FROM products
  SHOW COUNT_DISTINCT(view_sessions)
  GROUP BY product_id
  SINCE this_month
  ```
