Навигационные функции
Навигационные функции получают простые (не агрегированные) значения выражения из другой строки запроса в той же секции.
Important
|
Функции
Из-за этого результаты функций
|
SELECT
id,
salary,
FIRST_VALUE(salary) OVER (ORDER BY salary),
LAST_VALUE(salary) OVER (ORDER BY salary),
NTH_VALUE(salary, 2) OVER (ORDER BY salary),
LAG(salary) OVER (ORDER BY salary),
LEAD(salary) OVER (ORDER BY salary)
FROM employee
ORDER BY salary;
id salary first_value last_value nth_value lag lead -- ------ ----------- ---------- --------- ------ ------ 3 8.00 8.00 8.00 <null> <null> 9.00 4 9.00 8.00 9.00 9.00 8.00 10.00 1 10.00 8.00 10.00 9.00 9.00 10.00 5 10.00 8.00 10.00 9.00 10.00 12.00 2 12.00 8.00 12.00 9.00 10.00 <null>
Вариант с изменённой рамкой окна для функций LAST_VALUE
и NTH_VALUE
SELECT
id,
salary,
FIRST_VALUE(salary) OVER (ORDER BY salary),
LAST_VALUE(salary) OVER w,
NTH_VALUE(salary, 2) OVER w,
LAG(salary) OVER (ORDER BY salary),
LEAD(salary) OVER (ORDER BY salary)
FROM employee
WINDOW
w AS (ORDER BY salary ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
ORDER BY salary;
id salary first_value last_value nth_value lag lead -- ------ ----------- ---------- --------- ------ ------ 3 8.00 8.00 12.00 9.00 <null> 9.00 4 9.00 8.00 12.00 9.00 8.00 10.00 1 10.00 8.00 12.00 9.00 9.00 10.00 5 10.00 8.00 12.00 9.00 10.00 12.00 2 12.00 8.00 12.00 9.00 10.00 <null>