본문으로 바로가기
본문으로 바로가기

leadInFrame

정렬된 프레임 내에서 현재 행으로부터 offset 행 이후에 위치한 행에서 평가된 값을 반환합니다.

참고

leadInFrame의 동작은 표준 SQL lead 윈도 함수와 다릅니다. ClickHouse 윈도 함수 leadInFrame은 윈도 프레임을 그대로 따릅니다. lead와 동일한 동작을 얻으려면 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING을 사용하십시오.

구문

leadInFrame(x[, offset[, default]])
  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])

윈도우 함수 구문에 대한 자세한 내용은 Window Functions - Syntax를 참조하십시오.

파라미터

  • x — 컬럼 이름.
  • offset — 적용할 오프셋. (U)Int*. (선택 사항 - 기본값은 1).
  • default — 계산된 행이 윈도우 프레임 경계를 벗어날 경우 반환할 값. (선택 사항 - 생략 시 컬럼 타입의 기본값).

반환 값

  • 정렬된 프레임 내에서 현재 행으로부터 offset 행 뒤에 있는 행에서 평가된 값.

예시

이 예시는 노벨상 수상자의 역사적 데이터를 살펴보고, leadInFrame 함수를 사용하여 물리학 부문에서 연이은 수상자 목록을 반환합니다.

쿼리:

CREATE OR REPLACE VIEW nobel_prize_laureates
AS SELECT *
FROM file('nobel_laureates_data.csv');
SELECT
    fullName,
    leadInFrame(year, 1, year) OVER (PARTITION BY category ORDER BY year ASC
      ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
    ) AS year,
    category,
    motivation
FROM nobel_prize_laureates
WHERE category = 'physics'
ORDER BY year DESC
LIMIT 9

결과:

   ┌─fullName─────────┬─year─┬─category─┬─motivation─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
1. │ Anne L Huillier  │ 2023 │ physics  │ for experimental methods that generate attosecond pulses of light for the study of electron dynamics in matter                     │
2. │ Pierre Agostini  │ 2023 │ physics  │ for experimental methods that generate attosecond pulses of light for the study of electron dynamics in matter                     │
3. │ Ferenc Krausz    │ 2023 │ physics  │ for experimental methods that generate attosecond pulses of light for the study of electron dynamics in matter                     │
4. │ Alain Aspect     │ 2022 │ physics  │ for experiments with entangled photons establishing the violation of Bell inequalities and  pioneering quantum information science │
5. │ Anton Zeilinger  │ 2022 │ physics  │ for experiments with entangled photons establishing the violation of Bell inequalities and  pioneering quantum information science │
6. │ John Clauser     │ 2022 │ physics  │ for experiments with entangled photons establishing the violation of Bell inequalities and  pioneering quantum information science │
7. │ Giorgio Parisi   │ 2021 │ physics  │ for the discovery of the interplay of disorder and fluctuations in physical systems from atomic to planetary scales                │
8. │ Klaus Hasselmann │ 2021 │ physics  │ for the physical modelling of Earths climate quantifying variability and reliably predicting global warming                        │
9. │ Syukuro Manabe   │ 2021 │ physics  │ for the physical modelling of Earths climate quantifying variability and reliably predicting global warming                        │
   └──────────────────┴──────┴──────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘