Search Postgresql Archives

Re: Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 10 Dec 2007 12:23:49 +0000 (GMT)
Ashish Karalkar <ashish_postgre@xxxxxxxxxxx> 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


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux