From: | "Dan Winslow" <danwinslow(at)cox(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Seeking help with a query.... |
Date: | 2003-03-21 15:51:40 |
Message-ID: | gyGea.116460$JE5.71106@news2.central.cox.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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.
From | Date | Subject | |
---|---|---|---|
Next Message | mallah | 2003-03-21 16:32:11 | Re: explain |
Previous Message | Tom Lane | 2003-03-21 15:07:47 | Re: cast of integer to bool doesn't work (anymore?) |