X-Original-To: pgsql-sql@postgresql.org Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 6885A475AFF for ; Fri, 21 Mar 2003 13:10:33 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 383FA43A666; Fri, 21 Mar 2003 13:10:33 -0500 (EST) From: "Dan Winslow" X-Newsgroups: comp.databases.postgresql.sql Subject: Diffcult query Lines: 28 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: Date: Fri, 21 Mar 2003 17:41:29 GMT X-Complaints-To: abuse@cox.net Organization: Cox Communications To: pgsql-sql@postgresql.org X-Archive-Number: 200303/504 X-Sequence-Number: 12543 Hi folks. This is giving me fits. I feel like it oughta be simple, but apparantly its not...I think. Given a table : create table tablea ( code1 varchar(32), code2 varchar(32), cost int ); and the rows code1 code2 cost ---------------------------------- "aaa" "bbb" 2 "ddd" "eee" 3 "bbb" "aaa" 6 "ggg" "hhh" 4 I need a ( preferably single ) query that will sum the costs for all unique 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 case where ("bbb","aaa") is considered a seperate pair. Any ideas would be much appreciated.