Returns the value at the Nth position in the window frame.
Same as input expressionDiperbarui: 13 Jun 2026NTH_VALUE(expression, n) OVER ([PARTITION BY partition_expression] ORDER BY sort_expression [frame_clause])Column or expression whose value is retrieved
Row position (1-indexed)
Divides data into groups
Determines the ordering
1 SELECT 2 category, 3 product_name, 4 sales, 5 NTH_VALUE(product_name, 2) OVER ( 6 PARTITION BY category 7 ORDER BY sales DESC 8 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 9 ) as second_best 10 FROM `project.dataset.products`;
Finds the product with the second highest sales.
| category | product_name | sales | second_best |
|---|---|---|---|
| Electronics | iPhone | 50000 | MacBook |
| Electronics | MacBook | 35000 | MacBook |
| Electronics | iPad | 20000 | MacBook |
1 SELECT 2 game_id, 3 player_name, 4 score, 5 NTH_VALUE(player_name, 3) OVER ( 6 PARTITION BY game_id ORDER BY score DESC 7 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING 8 ) as bronze_medal 9 FROM `project.dataset.game_scores`;
Finds the player with the third highest score (bronze medal).
Sudah paham NTH_VALUE? Latih langsung di browser
Latihan interaktif, langsung di browser.