Count distinct values with OVER(PARTITION BY id)
No, as the error message states, DISTINCT is not implemented with windows functions. Aplying info from this link into your case you could use something like: WITH uniques AS ( SELECT congestion.id_element, COUNT(DISTINCT congestion.week_nb) AS unique_references FROM congestion WHERE congestion.date >= ‘2014.01.01’ AND congestion.date <= ‘2014.12.31’ GROUP BY congestion.id_element ) SELECT congestion.date, congestion.week_nb, congestion.id_congestion, congestion.id_element, … Read more