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

> 选择列中最后遇到的值。

# anyLast

<div id="anyLast">
  ## anyLast
</div>

Introduced in：v1.1.0

选取列中最后遇到的值。

<Warning>
  由于查询可能以任意顺序执行，因此此函数的结果是不确定的。
  如果你需要任意但确定的结果，请使用函数 [min](/zh/reference/functions/aggregate-functions/min) 或 [max](/zh/reference/functions/aggregate-functions/max)。
</Warning>

默认情况下，此函数绝不会返回 NULL，即会忽略输入列中的 NULL 值。
但是，如果函数与 `RESPECT NULLS` modifier 一起使用，则无论该值是否为 NULL，都会返回最后读取到的值。

**语法**

```sql theme={null}
anyLast(column) [RESPECT NULLS]
```

**别名**: `last_value`

**参数**

* `column` — 列名。[`Any`](/zh/reference/data-types)

**返回值**

返回最后遇到的值。[`Any`](/zh/reference/data-types)

**示例**

**使用示例**

```sql title=Query theme={null}
CREATE TABLE tab(city Nullable(String)) ENGINE=Memory;
INSERT INTO tab (city) VALUES ('Amsterdam'), (NULL), ('New York'), ('Tokyo'), ('Valencia'), (NULL);
SELECT anyLast(city), anyLastRespectNulls(city) FROM tab;
```

```response title=Response theme={null}
┌─anyLast(city)─┬─anyLastRespectNulls(city)─┐
│ Valencia      │ ᴺᵁᴸᴸ                      │
└───────────────┴───────────────────────────┘
```
