[SQL] Seeking help with a query....

2003-03-21 Thread Dan Winslow
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,
  costint
);

And the rows

code1code2cost
-
ab2
de4
ba6
fg1

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.




---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


[SQL] Diffcult query

2003-03-21 Thread Dan Winslow
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),
  costint
);

and the rows

code1code2cost
--
"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.



---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly