LAST_VALUE()
LAST_VALUE() is a SQL function in the Window Functions category. Returns the last value in a window frame. Needs carefully specified frame boundaries. The syntax is LAST_VALUE(column) OVER (PARTITION BY col ORDER BY col RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING). It accepts column. It returns last value in frame. A typical example: SELECT name, salary, LAST_VALUE(name) OVER ( ORDER BY salary ASC RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS lowest_paid FROM employees; -- Every row shows the lowest paid employee name A close relative is ROW_NUMBER(), which assigns a unique sequential integer to each row within its partition (1, 2, 3...). A close relative is RANK(), which similar to ROW_NUMBER but gives the same rank to equal values. Leaves gaps in ranking. A close relative is DENSE_RANK(), which like RANK but without gaps. Equal values get the same rank, and the next number follows sequentially.