X-Original-To: pgsql-sql@postgresql.org Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id 24E244762FE for ; Fri, 21 Mar 2003 14:46:06 -0500 (EST) Received: from [216.135.165.74] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2914130; Fri, 21 Mar 2003 11:45:54 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Dan Winslow" , pgsql-sql@postgresql.org Subject: Re: Diffcult query Date: Fri, 21 Mar 2003 11:45:58 -0800 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200303211145.58768.josh@agliodbs.com> X-Archive-Number: 200303/512 X-Sequence-Number: 12551 Dan, > Hi folks. This is giving me fits. I feel like it oughta be simple, but > apparantly its not...I think. > I need a ( preferably single ) query that will sum the costs for all uniq= ue > pairs of codes, without regard to column order. That is, for summing > purposes, rows 1 and 3 are identical, and should produce the sum of 8 for > the unordered pair("aaa","bbb"). It should also, of course, prevent the c= ase > where ("bbb","aaa") is considered a seperate pair. Any ideas would be much > appreciated. It's not simple, because your DB design is poorly normalized. My first=20 suggestion would be to make some design changes to your schema. Is that=20 possible? --=20 -Josh Berkus Aglio Database Solutions San Francisco