unsure of how to query for desired data/output - Mailing list pgsql-novice

From Carol Cheung
Subject unsure of how to query for desired data/output
Date
Msg-id 4934123D.5040109@consumercontact.com
Whole thread Raw
Responses Re: unsure of how to query for desired data/output
List 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 by date:

Previous
From: Bruce Hyatt
Date:
Subject: Re: Postgresql Books
Next
From: "Andreas Junius"
Date:
Subject: SQL Status:42883