Consecutive row count query

Поиск
Список
Период
Сортировка
От Leon Stringer
Тема Consecutive row count query
Дата
Msg-id 1111090884.22783.5.camel@localhost.localdomain
обсуждение исходный текст
Ответы Re: Consecutive row count query  (Bruno Wolff III <bruno@wolff.to>)
Re: Consecutive row count query  (Jaime Casanova <systemguards@gmail.com>)
Re: Consecutive row count query  (Greg Stark <gsstark@mit.edu>)
Re: Consecutive row count query  (Andrew Hammond <ahammond@ca.afilias.info>)
Re: Consecutive row count query  (Leon Stringer <leon.stringer@ntlworld.com>)
Список pgsql-sql
Hi,

I wondered if anyone could answer the following question:

If I have a table such as the one below:

col1   col_order
-----------
Apple  1
Apple  2
Orange 3
Banana 4
Apple  5

Is there a way I can get the following results:

Apple  2
Orange 1
Banana 1
Apple  1

i.e. Each row is printed ordered by col_order but consecutive
appearances of the same col1 result in only a single line in the result
with the number of consecutive appearances.

Obviously I could store the table as:

col1   col_order col_count
--------------------------
Apple  1         2
Orange 2         1
Banana 3         1
Apple  4         1

But since (in my intended table) most rows will have col_count = 1, this
seems like unnecessary normalization (and semantically "wrong").

Thanks in advance for any help,

Leon Stringer




В списке pgsql-sql по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: lower and unicode
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Consecutive row count query