Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E09F76329C3 for ; Thu, 23 Jul 2009 05:05:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 47074-01 for ; Thu, 23 Jul 2009 05:05:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lion02.hosting.nl (lion02.hosting.nl [62.129.139.91]) by mail.postgresql.org (Postfix) with ESMTP id 0F542633349 for ; Thu, 23 Jul 2009 05:03:34 -0300 (ADT) Received: from lionhead.nl (static.kpn.net [83.232.157.250] (may be forged)) by lion02.hosting.nl (8.13.8/8.13.8) with ESMTP id n6N78mpp010513 for ; Thu, 23 Jul 2009 09:08:48 +0200 Received: from lionhead2.lionhead.nl (localhost.localdomain [127.0.0.1]) by lionhead.nl (8.13.8/8.13.8) with ESMTP id n6N83VqJ000980 for ; Thu, 23 Jul 2009 10:03:31 +0200 Date: Thu, 23 Jul 2009 10:03:31 +0200 From: "David Weilers" To: pgsql-sql Message-ID: In-Reply-To: <200907222104.38931.peter_e@gmx.net> Subject: Re: Double aggregate problem x-scalix-Hops: 1 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.819 tagged_above=-10 required=5 tests=MIME_QP_LONG_LINE=1.819 X-Spam-Level: * X-Archive-Number: 200907/115 X-Sequence-Number: 32856 Hello, I have the following tables: CREATE TABLE tblvacature ( id serial PRIMARY KEY, account int NOT NULL REFERENCES tblaccount (id) ON DELETE CASCADE, title varchar(128), bedrijfsprofiel text, functieomschrijving text, functieeisen text, arbeidsvoorwaarden text overig text, sollicitatieinfo text, inserted timestamp DEFAULT now() ); CREATE TABLE tblvacaturesector ( vacature int NOT NULL REFERENCES=20 tblvacature (id) ON DELETE CASCADE, sector int NOT NULL REFERENCES=20 tblsector (id) ON DELETE CASCADE ); select * from tblvacaturesector where vacature =3D 11; vacature | sector ----------+-------- 11 | 5 11 | 2 CREATE TABLE tblvacatureprovincie ( vacature int NOT NULL REFERENCES=20 tblvacature (id) ON DELETE CASCADE, provincie int NOT NULL REFERENCES=20 tblprovincie (id) ON DELETE CASCADE ); select * from tblvacatureprovincie where vacature =3D 11; vacature | provincie ----------+----------- 11 | 7 11 | 1 11 | 8 CREATE TABLE tblprovincie ( id serial PRIMARY KEY, land int NOT NULL REFERENCES tblland (id) ON DELETE RESTRICT, name varchar(128) ); select * from tblprovincie; id | land | name ----+------+----------------- 1 | 1 | Noord-Holland 2 | 1 | Zuid-Holland 3 | 1 | Groningen 4 | 2 | Brabant 5 | 1 | Utrecht 6 | 2 | Antwerpen 7 | 2 | Limburg 8 | 2 | Oost-Vlaanderen CREATE TABLE tblsector ( id serial PRIMARY KEY, name varchar(128) ); select * from tblsector; id | name ----+--------- 4 | Aap 1 | Cool 5 | Eerder 2 | Gaafjes 6 | Later 3 | Netjes 11 | ICT I hope that's enough information? > -----Oorspronkelijk bericht----- > Van: Peter Eisentraut [mailto:peter_e@gmx.net] > Verzonden: woensdag 22 juli 2009 20:05 > Aan: pgsql-sql@postgresql.org > CC: David Weilers > Onderwerp: Re: [SQL] Double aggregate problem >=20 > On Wednesday 22 July 2009 19:16:21 David Weilers wrote: > > I have the following query: > > > > select v.id, array_to_string(array_accum(s.name),', ') as sector , > > array_to_string(array_accum(p.name),', ') as provincie from=20 tblvacature > > v, tblaccount a , tblvacaturesector vs, tblsector s , > > tblvacatureprovincie vp, tblprovincie p where v.id =3D 11 and=20 v.account =3D > > a.id and vs.vacature =3D v.id and s.id =3D vs.sector and vp.vacature =3D= =20 v.id > > and p.id =3D vp.provincie group by v.id, v.inserted order by=20 v.inserted > > desc > > > > That currently produces the following output: >=20 > No one is going to be able to reproduce that without the table=20 definitions and > data. >=20