> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-home-button.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# anyIf

> Ejemplo de uso del combinador anyIf

<div id="description">
  ## Descripción
</div>

El combinador [`If`](/es/reference/functions/aggregate-functions/combinators#-if) se puede aplicar a la función de agregado [`any`](/es/reference/functions/aggregate-functions/any)
para seleccionar el primer elemento encontrado en una columna determinada
que cumpla la condición indicada.

<div id="example-usage">
  ## Ejemplo de uso
</div>

En este ejemplo, crearemos una tabla que almacena datos de ventas con indicadores de éxito
y usaremos `anyIf` para seleccionar los primeros `transaction_id` con importes por encima y
por debajo de 200.

Primero creamos una tabla e insertamos datos en ella:

```sql title="Query" theme={null}
CREATE TABLE sales(
    transaction_id UInt32,
    amount Decimal(10,2),
    is_successful UInt8
) 
ENGINE = MergeTree()
ORDER BY tuple();

INSERT INTO sales VALUES
    (1, 100.00, 1),
    (2, 150.00, 1),
    (3, 155.00, 0),
    (4, 300.00, 1),
    (5, 250.50, 0),
    (6, 175.25, 1);
```

```sql theme={null}
SELECT
    anyIf(transaction_id, amount < 200) AS tid_lt_200,
    anyIf(transaction_id, amount > 200) AS tid_gt_200
FROM sales;
```

```response title="Response" theme={null}
┌─tid_lt_200─┬─tid_gt_200─┐
│          1 │          4 │
└────────────┴────────────┘
```

<div id="see-also">
  ## Véase también
</div>

* [`any`](/es/reference/functions/aggregate-functions/any)
* [`If combinador`](/es/reference/functions/aggregate-functions/combinators#-if)
