I am trying to create a new column that counts unique partitions of another column.
ColA *NewCol ------------ A 1 A 1 A 1 B 2 B 2 C 3 C 3 C 3
I have tried using
DENSE_RANK() OVER (PARTITION BY ColA ORDER BY ColA)
but each partition’s count stays the same at 1.
How would I go about getting results for *NewCol?
Advertisement
Answer
You are looking for just the order by
select dense_rank(*) over (order by cola)
The partition by
causes the value to be 1
for all cola
, because only one value is considered in each partition.