Skip to main content
SQL โ€ข LESSON 160

Last Value

How can we retrieve the lowest salary across the entire department frame?

Advancedโฑ 3 Minutesโญ 1730 XP
๐Ÿค” THE QUESTION

How can we retrieve the lowest salary across the entire department frame?

๐Ÿ’ก WHAT IS IT?

LAST_VALUE() with frame ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING captures the final row in the partition.

๐ŸŽฏ WHAT IS IT USED FOR?

Full-window extremes, comparing against lowest tier in a partition, range spreads.

๐Ÿ’ป EXAMPLE
SELECT
department_id,
name,
salary,
LAST_VALUE(salary) OVER (
    PARTITION BY department_id
    ORDER BY salary
    ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS lowest_salary
FROM employees;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for Last Value.

  • โœ“ LAST_VALUE()
  • โœ“ Full frame specification
  • โœ“ UNBOUNDED FOLLOWING
  • โœ“ Partition boundary extraction