문제

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