unsure of how to query for desired data/output

Поиск
Список
Период
Сортировка
От Carol Cheung
Тема unsure of how to query for desired data/output
Дата
Msg-id 4934123D.5040109@consumercontact.com
обсуждение исходный текст
Ответы Re: unsure of how to query for desired data/output  ("Rodrigo E. De León Plicet" <rdeleonp@gmail.com>)
Список pgsql-novice
Hi,
I have a table with a column of integers called 'status'. A number may
appear 0+ times in this column. For example,

  status
--------
   25
   28
   28
...

I know I can get counts of the each status using select count(status),
status from test_table group by status;

Let's say I have some lists of numbers, like so:

25
3,17
40,28,6
17

25 appears in the status column 3 times.
3 appears in the status column 6 times.
17 appears in the status column 2 times.
40 appears in the status column 0 times.
6 appears in the status column 1 time.
28 appears in the status column 2 times

Is it possible to get the following based on the above list of numbers:

25|3
3,17|8
40,28,6|3
17|2

the first column is the list of status, the second column is the sum of
the counts of the status codes appearing on the left of the "|"

Does anyone have any ideas on how to get this output without executing 4
separate queries?

Thanks.




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

Предыдущее
От: Bruce Hyatt
Дата:
Сообщение: Re: Postgresql Books
Следующее
От: "Andreas Junius"
Дата:
Сообщение: SQL Status:42883