Returns the last value in the window frame for each row.
Same as input expressionDiperbarui: 13 Jun 2026LAST_VALUE(expression) OVER ([PARTITION BY partition_expression] ORDER BY sort_expression [frame_clause])Column or expression whose value is retrieved
Divides data into groups
Determines the ordering
1 SELECT 2 department, 3 name, 4 salary, 5 LAST_VALUE(name) OVER ( 6 PARTITION BY department 7 ORDER BY salary 8 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 9 ) as highest_paid 10 FROM `project.dataset.employees`;
Finds the highest-paid employee per department.
| department | name | salary | highest_paid |
|---|---|---|---|
| Sales | David | 50000 | Alice |
| Sales | Bob | 80000 | Alice |
| Sales | Alice | 120000 | Alice |
1 SELECT 2 order_id, 3 status, 4 updated_at, 5 LAST_VALUE(status) OVER ( 6 PARTITION BY order_id 7 ORDER BY updated_at 8 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 9 ) as current_status 10 FROM `project.dataset.order_history`;
Gets the most recent status for each order.
Sudah paham LAST_VALUE? Latih langsung di browser
Latihan interaktif, langsung di browser.