sql question

From: Herbert Liechti <Herbert(dot)Liechti(at)thinx(dot)ch>
To: postgres <pgsql-general(at)postgreSQL(dot)org>
Subject: sql question
Date: 1999-11-17 19:53:33
Message-ID: 383307BC.D8DA8C10@thinx.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a sql problem which I can't solve. The following table is defined

create table AdressGroup
(
AdrGroup_Id INTEGER NOT NULL
DEFAULT NEXTVAL('adrverw_id_seq'),
Zeit DATETIME NOT NULL,
Group_Id INTEGER NOT NULL,
Adress_Id INTEGER NOT NULL
);

The table assigns adresses to adressgroups.

I'd like to select the adresses which belongs to one specific adressGroup and to no other group. If an adress has more than one entry in the AdressGroup
table it should not be in the projection.

I tried the following:

SELECT * FROM adressGroup
WHERE Group_Id = 6
AND EXISTS( SELECT AdrGroup_Id FROM adressGroup ag_alias
WHERE adressGroup.AdrGroup_Id = ag_alias.AdrGroup_Id
GROUP BY AdrGroup_Id HAVING COUNT(*) == 1 );

When I do this I get the following error:
ERROR: rewrite: aggregate column of view must be at rigth side in qual
ERROR: rewrite: aggregate column of view must be at rigth side in qual

Does anybody knows the solution? Thanks

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti E-Mail: Herbert(dot)Liechti(at)thinx(dot)ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Browse pgsql-general by date

  From Date Subject
Next Message J. Roeleveld 1999-11-17 20:21:52 Problem with CREATE RULE <something> ON DELETE (PostgreSQL only executes the first expression)
Previous Message Jason Leach 1999-11-17 08:29:46 Java Ex.