Re: Query - Mailing list pgsql-general

From Ivan Sergio Borgonovo
Subject Re: Query
Date
Msg-id 20071210135942.31f17904@webthatworks.it
Whole thread Raw
In response to Query  (Ashish Karalkar <ashish_postgre@yahoo.co.in>)
List pgsql-general
On Mon, 10 Dec 2007 12:23:49 +0000 (GMT)
Ashish Karalkar <ashish_postgre@yahoo.co.in> wrote:

> Hello there,
> I am having data in table something like below:
>
> user_id        type_id
> 1                    1
> 1                    2
> 2                    1
> 3                    3
> 4                    3
> 5                    1
> 1                   10
> 7                    6
>
> What i want is the count of all user group by type_id  who are
> subscribed to only one type e.g
>
> type_id   count
> 1                2

  1                3

> 6                     1

This is not to "only one type" or I didn't get the question.

Something like

create table pippo ( user_id int, type_id int);
insert into pippo values(1,1);
insert into pippo values(1,2);
insert into pippo values(2,1);
insert into pippo values(3,3);
insert into pippo values(4,3);
insert into pippo values(5,1);
insert into pippo values(1,10);
insert into pippo values(7,6);


select type_id, count(*) from pippo group by type_id having
count(*)=1;

10;1
6;1
2;1


--
Ivan Sergio Borgonovo
http://www.webthatworks.it


pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Query
Next
From: Ted Byers
Date:
Subject: Re: Simpler dump?