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

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

From: T E Schmitz <mailreg(at)numerixtechnology(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:19:11
Message-ID: 414F02FF.8000603@numerixtechnology.de (view raw or flat)
Thread:
Lists: pgsql-sql
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'.

SELECT
BRAND_NAME,MODEL_NAME
FROM TYPE
left outer join MODEL  on MODEL_PK =TYPE.MODEL_FK
left outer join BRAND  on BRAND_PK =MODEL.BRAND_FK
group by BRAND.BRAND_NAME,MODEL_NAME
having count(*)>1

intersect

SELECT
BRAND_NAME,MODEL.MODEL_NAME
FROM TYPE
left outer join MODEL  on MODEL_PK =TYPE.MODEL_FK
left outer join BRAND  on BRAND_PK =MODEL.BRAND_FK
where TYPE_NAME='xyz'
group by BRAND.BRAND_NAME,MODEL_NAME


-- 


Regards/Gruß,

Tarlika Elisabeth Schmitz



-- 


Regards/Gruß,

Tarlika Elisabeth Schmitz

Responses

pgsql-sql by date

Next:From: Josh BerkusDate: 2004-09-20 16:30:44
Subject: Re: Test for file exists?
Previous:From: T E SchmitzDate: 2004-09-20 15:14:46
Subject: COUNT(*) to find records which have a certain number of dependencies ?

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