Search code examples
sqlcountaginity

Cumulative count of repeated values, starting at 1


I have a list of individual ID keys that have duplicates. I'd like to deduplicate this by counting the instance of each repeated key. I can count the cumulative total, or count the number of repeated instances, but not count incrementally from 1 through x at the next first instance of the ID key.

Example, this is what I'd like to achieve enter image description here


Solution

  • In SQL Query

    Select IndividualKey,Row_number()OVER(PARTITION BY IndividualKey ORDER BY (SELECT NULL))ID From Table