Assigns a unique sequential number to each row within a partition, starting at 1. No duplicate values are assigned.
INT64Diperbarui: 13 Jun 2026ROW_NUMBER() OVER ([PARTITION BY partition_expression] ORDER BY sort_expression)Determines the numbering order
Divides data into groups (optional)
1 SELECT 2 name, 3 department, 4 salary, 5 ROW_NUMBER() OVER (ORDER BY salary DESC) as salary_rank 6 FROM `project.dataset.employees`;
Assign row numbers ordered by highest salary first.
| name | department | salary | salary_rank |
|---|---|---|---|
| Alice | Engineering | 120000 | 1 |
| Bob | Sales | 110000 | 2 |
| Charlie | Engineering | 100000 | 3 |
1 SELECT 2 customer_id, 3 order_date, 4 amount, 5 ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) as order_num 6 FROM `project.dataset.orders`;
Assign row numbers per customer, with the most recent order numbered 1.
1 WITH ranked AS ( 2 SELECT *, 3 ROW_NUMBER() OVER (PARTITION BY email ORDER BY created_at DESC) as rn 4 FROM `project.dataset.users` 5 ) 6 SELECT * FROM ranked WHERE rn = 1;
Retrieve the most recent record per email address to deduplicate.
Sudah paham ROW_NUMBER? Latih langsung di browser
Latihan interaktif, langsung di browser.