Обсуждение: group number

Поиск
Список
Период
Сортировка

group number

От
Rene Romero Benavides
Дата:
Thank you very much for your attention.

I'm facing a mental block to achieve this in a performant manner:

Input:
a
a
b
c
c
c
d

Desired output:

a 1
a 1
b 2
c 3
c 3
c 3
d 4


Any suggestions? Have a good day (night, afternoon or evening) and greetings from México City.

Re: group number

От
Pavel Stehule
Дата:
Hello

postgres=# select v, dense_rank() over(order by v) from unnest('{a,a,b,c,c,c,d}'::varchar[]) g(v);
 v | dense_rank
---+------------
 a |          1
 a |          1
 b |          2
 c |          3
 c |          3
 c |          3
 d |          4
(7 rows)

Regards

Pavel


2014-05-09 22:15 GMT+02:00 Rene Romero Benavides <rene.romero.b@gmail.com>:
Thank you very much for your attention.

I'm facing a mental block to achieve this in a performant manner:

Input:
a
a
b
c
c
c
d

Desired output:

a 1
a 1
b 2
c 3
c 3
c 3
d 4


Any suggestions? Have a good day (night, afternoon or evening) and greetings from México City.