I have employee records on Google BigQuery containing : employee_identifier, manager_identifier and date_of_the_record
My goal is to calculate, through an SQL query, for each record, the number of managers an employee had until the date of the record.
I have tried different clauses : OVER (PARTITION BY / ROWS UNBOUNDED PRECEDING), etc.
What I have tried is :
SELECT
employee_identifier,
date_of_the_record,
COUNT(DISTINCT manager_identifier)
OVER (PARTITION BY employee_identifier ORDER BY date_of_the_record ROWS UNBOUNDED PRECEDING) AS number_of_managers_until_date_of_the_record
FROM employee_database
but the DISTINCT clause is forbidden with ORDER BY.
To sum it up, I just want the number of (distinct) managers an employee had until the date of the record.