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

lead

정렬된 프레임에서 현재 행으로부터 offset 행 뒤에 위치한 행에서 계산된 값을 반환합니다. 이 함수는 leadInFrame과 유사하지만, 항상 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 프레임을 사용합니다.

구문

lead(x[, offset[, default]])
  OVER ([[PARTITION BY grouping_column] [ORDER BY sorting_column]] | [window_name])
FROM table_name
WINDOW window_name as ([[PARTITION BY grouping_column] [ORDER BY sorting_column])

윈도우 함수 구문에 대한 더 자세한 내용은 윈도우 함수 - 구문을 참조하십시오.

매개변수

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

반환 값

  • 정렬된 윈도우 프레임 내에서 현재 행 이후 offset 행만큼 떨어진 행에서 평가된 값.

예시

다음 예시는 노벨상 수상자에 대한 과거 데이터를 살펴보고, 물리학 분야에서 연속된 수상자 목록을 반환하기 위해 lead 함수를 사용합니다.

CREATE OR REPLACE VIEW nobel_prize_laureates
AS SELECT *
FROM file('nobel_laureates_data.csv');
SELECT
    fullName,
    lead(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                        │
   └──────────────────┴──────┴──────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘