@@ -43,16 +43,18 @@ VALUES
4343
4444-- Use NTH_VALUE to retrieve the first name of the employee with the second highest salary
4545SELECT employee_id, first_name, last_name, salary,
46- NTH_VALUE(first_name, 2 ) OVER (ORDER BY salary DESC ) AS second_highest_salary_first_name
46+ NTH_VALUE(first_name, 2 ) OVER (ORDER BY salary DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS second_highest_salary_first_name
4747FROM employees;
4848
49- employee_id | first_name | last_name | salary | second_highest_salary_first_name
50- -- ----------+------------+-----------+---------+----------------------------------
51- 4 | Mary | Williams | 7000 .00 | Jane
52- 2 | Jane | Smith | 6000 .00 | Jane
53- 3 | David | Johnson | 5500 .00 | Jane
54- 1 | John | Doe | 5000 .00 | Jane
55- 5 | Michael | Brown | 4500 .00 | Jane
49+ ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
50+ │ employee_id │ first_name │ last_name │ salary │ second_highest_salary_first_name │
51+ ├─────────────────┼──────────────────┼──────────────────┼──────────────────────────┼──────────────────────────────────┤
52+ │ 4 │ Mary │ Williams │ 7000 .00 │ Jane │
53+ │ 2 │ Jane │ Smith │ 6000 .00 │ Jane │
54+ │ 3 │ David │ Johnson │ 5500 .00 │ Jane │
55+ │ 1 │ John │ Doe │ 5000 .00 │ Jane │
56+ │ 5 │ Michael │ Brown │ 4500 .00 │ Jane │
57+ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
5658```
5759
5860This example excludes the NULL values from the window frame with the ` IGNORE NULLS ` option:
0 commit comments