Skip site navigation (1) Skip section navigation (2)

Re: COUNT(*) to find records which have a certain number of

From: Martin Knipper <martin(at)mk-os(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: COUNT(*) to find records which have a certain number of
Date: 2004-09-20 16:44:45
Message-ID: 414F08FD.3080200@mk-os.de (view raw or flat)
Thread:
Lists: pgsql-sql
Am 20.09.2004 18:19 schrieb T E Schmitz:

> I figured it eventually. (The only thing I don't know is where to put
> the ORDER BY.)
> 
> 
>>I want to select only those BRAND/MODEL combinations, where the MODEL 
>>has more than one TYPE, but only where one of those has TYPE_NAME='xyz'.
>>I am not interested in MODELs with multiple TYPEs where none of them are 
>>called 'xyz'.
> 
> 

Try this:

select b.brand_name,m.model_name,count(*) from model m inner join
brand b on m.brand_fk=b.brand_pk inner join type t on
m.model_pk=t.model_fk where t.type_name='xyz' group by
b.brand_name,m.model_name having count(m.model_name)>0;

Greetings,

Martin

-- 
Martin Knipper
www  : http://www.mk-os.de
Mail : knipper(at)mk-os(dot)de


In response to

Responses

pgsql-sql by date

Next:From: T E SchmitzDate: 2004-09-20 17:59:39
Subject: Re: COUNT(*) to find records which have a certain number of
Previous:From: Rod TaylorDate: 2004-09-20 16:31:36
Subject: Re: COUNT(*) to find records which have a certain number of

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group