Вопрос

Is it possible to populate a column in SQL that looks like this? Original column on the left, the one I want on the right.

A...1
B...1
C...1
D...1
A...2
C...2
E...1
A...3
D...2

i.e. the first occurrence of each letter is 1, the second occurrence of each letter (going down) is a 2, the third occurrence of each letter is a 3 etc.

Это было полезно?

Решение

  SELECT col1,
  ROW_NUMBER( ) OVER (PARTITION BY
  col1 ORDER BY col1
  NULLS LAST) SRLNO
  FROM table;

Replace col1 with 'column name'

and

table with 'table name'

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top