ROW_NUMBER() OVER PARTITON BY Syntax in Bigquery
Use the ROW_NUMBER() over analytic functions to Calculate ROW_NUMBER. Analytic functions are evaluated after aggregation (GROUP BY and non-analytic aggregate functions)
The following query finds the early employee in each department:
SELECT firstname, department, startdate,
ROW_NUMBER() OVER ( PARTITION BY department ORDER BY startdate ) AS rank
FROM Employees;
you can extend this query to only see the top users,
Select A.* from ( SELECT firstname, department, startdate,
ROW_NUMBER() OVER ( PARTITION BY department ORDER BY startdate ) AS rownum
FROM Employees)A where A.rownum=1;
nVector
posted on 20 Sep 19Enjoy great content like this and a lot more !
Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds
Post Comment