Skip to main content
SQL • LESSON 159

First Value

How can we display the department's top salary on every employee's record?

Advanced3 Minutes1720 XP
🤔 THE QUESTION

How can we display the department's top salary on every employee's record?

💡 WHAT IS IT?

FIRST_VALUE(column) retrieves the value from the initial row of the window frame.

🎯 WHAT IS IT USED FOR?

Benchmarking employees against the department highest earner, baseline comparisons.

💻 EXAMPLE
SELECT
department_id,
name,
salary,
FIRST_VALUE(salary) OVER (
    PARTITION BY department_id
    ORDER BY salary DESC
) AS highest_salary
FROM employees;

🎯 Mission Objectives

Practice typing production-grade SQL code for First Value.

  • FIRST_VALUE()
  • Top boundary lookup
  • Partition maximum reference
  • Comparative reporting