Simply, the level value could only be 0, 1, 2, 3, it means the maxium event action stage that one user could reach.
## retention(cond1, cond2, ...)
## retention {#retention}
Retention refers to the ability of a company or product to retain its customers over some specified periods.
Analytical function that shows how much
certain conditions, for example, retention of dynamics/level [site traffic statistics](https://yandex.ru/support/partner2/statistics/metrika-visitors-statistics.html?lang=en).
`cond1`, `cond2` ... is from one to 32 arguments of type UInt8 that indicate whether a certain condition was met for the event
The function takes as arguments a set of conditions from 1 to 32 arguments of type `UInt8` that indicate whether a certain condition was met for the event.
Any condition can be specified as an argument (as in [WHERE](../select.md#select-where)).
Example:
The conditions, except the first, apply in pairs: the result of the second will be true if the first and second are true, of the third if the first and fird are true, etc.
Consider you are doing a website analytics, intend to calculate the retention of customers
**Syntax**
This could be easily calculate by `retention`
```sql
retention(cond1,cond2,...,cond32);
```
**Parameters**
-`cond` — an expression that returns a `UInt8` result (1 or 0).
**Returned value**
The array of 1 or 0.
- 1 — condition was met for the event.
- 0 — condition wasn't met for the event.
Type: `UInt8`.
**Example**
Let's consider an example of calculating the `retention` function to determine site traffic.
Simply, `r1` means the number of unique visitors who met the `cond1` condition, `r2` means the number of unique visitors who met `cond1` and `cond2` conditions, `r3` means the number of unique visitors who met `cond1` and `cond3` conditions.
Result:
```text
┌─r1─┬─r2─┬─r3─┐
│ 5 │ 5 │ 5 │
└────┴────┴────┘
```
Where:
-`r1`- the number of unique visitors who visited the site during 2020-01-01 (the `cond1` condition).
-`r2`- the number of unique visitors who visited the site during a specific time period between 2020-01-01 and 2020-01-02 (`cond1` and `cond2` conditions).
-`r3`- the number of unique visitors who visited the site during a specific time period between 2020-01-01 and 2020-01-03 (`cond1` and `cond3` conditions).
В результате мы можем получить 0, 1, 2 или 3 в зависимости от действий пользователя.
## retention {#retention}
Аналитическая функция, которая показывает, насколько
выдерживаются те или иные условия, например, удержание динамики/уровня [посещаемости сайта](https://yandex.ru/support/partner2/statistics/metrika-visitors-statistics.html?lang=ru).
Функция принимает набор (от 1 до 32) логических условий, как в [WHERE](../select.md#select-where), и применяет их к заданному набору данных.
Условия, кроме первого, применяются попарно: результат второго будет истинным, если истинно первое и второе, третьего - если истинно первое и третье и т. д.
**Синтаксис**
```sql
retention(cond1,cond2,...,cond32)
```
**Параметры**
-`cond` — вычисляемое условие или выражение, которое возвращает `UInt8` результат (1/0).
**Возвращаемое значение**
Массив из 1 или 0.
- 1 — условие выполнено.
- 0 — условие не выполнено.
Тип: `UInt8`.
**Пример**
Рассмотрим пример расчета функции `retention` для определения посещаемости сайта.