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 7A794474E4F for ; Fri, 21 Mar 2003 10:57:37 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 6187443A666; Fri, 21 Mar 2003 10:57:37 -0500 (EST) From: "Dan Winslow" X-Newsgroups: comp.databases.postgresql.sql Subject: Seeking help with a query.... Lines: 30 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 15:51:40 GMT X-Complaints-To: abuse@cox.net Organization: Cox Communications To: pgsql-sql@postgresql.org X-Archive-Number: 200303/505 X-Sequence-Number: 12544 Hi folks, seeking help with a query that I thought was simple, but apparantly isn't, at least for someone with my knowledge level. Given a table : create table atable ( code1 char, code2 char, cost int ); And the rows code1 code2 cost ----------------------------- a b 2 d e 4 b a 6 f g 1 I need a ( preferably single ) query that will sum the costs for any matching pairs of codes regardless of order. That is, row 1 and row 3 concern the same pair of unordered codes (a,b), and the result should show that the (a,b) pair had a summed cost of 8. I am not able to change any of the environment or preconditions other than the query itself. I have tried so many approaches that they aren't even worth listing. Any suggestions would be very much appreciated.