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

# anyIf

> anyIf 组合器使用示例

<div id="description">
  ## 描述
</div>

[`If`](/zh/reference/functions/aggregate-functions/combinators#-if) 组合器可应用于 [`any`](/zh/reference/functions/aggregate-functions/any)
聚合函数，用于从给定列中选取第一个满足给定条件的元素。

<div id="example-usage">
  ## 示例用法
</div>

在本示例中，我们将创建一个用于存储销售数据及成功标志的表，
并使用 `anyIf` 分别选出金额高于和低于 200 的第一个 `transaction_id`。

我们先创建一个表，并向其中插入数据：

```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">
  ## 另请参阅
</div>

* [`any`](/zh/reference/functions/aggregate-functions/any)
* [`If 组合器`](/zh/reference/functions/aggregate-functions/combinators#-if)
