MySQLWindow FunctionsNTH_VALUE
LAST_VALUE

NTH_VALUEWindow Functions

Returns the nth value in the window frame.

Syntax

NTH_VALUE(expr, n) OVER (w)

Example

Enter values below to update the example in real time.

employee_id
department_id
salary
third_highest
employees
-- 부서 내 3번째로 높은 급여
SELECT employee_id, department_id, salary,
       NTH_VALUE(salary, 3) OVER (
         PARTITION BY department_id ORDER BY salary DESC
         ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
       ) AS third_highest
FROM employees;