> ## 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.

> last_value 윈도 함수에 대한 문서

# last_value

정렬된 프레임 내에서 계산된 마지막 값을 반환합니다. 기본적으로 `NULL` 인수는 무시되지만, `RESPECT NULLS` 수정자를 사용하여 이 동작을 변경할 수 있습니다.

**구문**

```sql theme={null}
last_value (column_name) [[RESPECT NULLS] | [IGNORE NULLS]]
  OVER ([[PARTITION BY grouping_column] [ORDER BY sorting_column] 
        [ROWS or RANGE expression_to_bound_rows_withing_the_group]] | [window_name])
FROM table_name
WINDOW window_name as ([[PARTITION BY grouping_column] [ORDER BY sorting_column])
```

별칭: `anyLast`.

<Note>
  `first_value(column_name)` 뒤에 선택적 수정자 `RESPECT NULLS`를 사용하면 `NULL` 인수가 건너뛰어지지 않습니다.
  자세한 내용은 [NULL 처리](/ko/reference/functions/aggregate-functions#null-processing)를 참조하십시오.

  별칭: `lastValueRespectNulls`
</Note>

윈도 함수의 구문에 대한 자세한 내용은 [윈도우 함수 - 구문](/ko/reference/functions/window-functions#syntax)을 참조하십시오.

**반환 값**

* 정렬된 프레임 내에서 계산된 마지막 값입니다.

**예시**

이 예시에서는 `last_value` 함수를 사용해 가상의 프리미어리그 축구 선수 연봉 데이터셋에서 최저 연봉 선수를 찾습니다.

```sql title="Query" theme={null}
DROP TABLE IF EXISTS salaries;
CREATE TABLE salaries
(
    `team` String,
    `player` String,
    `salary` UInt32,
    `position` String
)
Engine = Memory;

INSERT INTO salaries FORMAT VALUES
    ('Port Elizabeth Barbarians', 'Gary Chen', 196000, 'F'),
    ('New Coreystad Archdukes', 'Charles Juarez', 190000, 'F'),
    ('Port Elizabeth Barbarians', 'Michael Stanley', 100000, 'D'),
    ('New Coreystad Archdukes', 'Scott Harrison', 180000, 'D'),
    ('Port Elizabeth Barbarians', 'Robert George', 195000, 'M'),
    ('South Hampton Seagulls', 'Douglas Benson', 150000, 'M'),
    ('South Hampton Seagulls', 'James Henderson', 140000, 'M');
```

```sql title="Query" theme={null}
SELECT player, salary,
       last_value(player) OVER (ORDER BY salary DESC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS lowest_paid_player
FROM salaries;
```

```response title="Response" theme={null}
   ┌─player──────────┬─salary─┬─lowest_paid_player─┐
1. │ Gary Chen       │ 196000 │ Michael Stanley    │
2. │ Robert George   │ 195000 │ Michael Stanley    │
3. │ Charles Juarez  │ 190000 │ Michael Stanley    │
4. │ Scott Harrison  │ 180000 │ Michael Stanley    │
5. │ Douglas Benson  │ 150000 │ Michael Stanley    │
6. │ James Henderson │ 140000 │ Michael Stanley    │
7. │ Michael Stanley │ 100000 │ Michael Stanley    │
   └─────────────────┴────────┴────────────────────┘
```
