GBL_DO
GBL_DO

Reputation: 49

Rank Values by Partition in SQL

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?

Upvotes: 0

Views: 45

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271013

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.

Upvotes: 1

Related Questions