From: Bryan Emrys <bryan.emrys@gmail.com>
To: pgsql-sql@postgresql.org
Subject: SQL dealing with subquery
Date: Tue, 15 Jan 2008 10:04:29 -0800
Message-ID: <eee4647d0801151004t288b0819ocbc0cae8e0df7f24@mail.gmail.com> (raw)
Hi all,
I'm having a conceptual problem with a subquery here - any help would be
appreciated.
I have a table treaty_rates with columns payor, payee, rate where payor and
payee are countries.
Sample set:
'US','UK',5
'US','Ireland',5
'US','Netherlands',5
'US','China',10
'Canada','US',0
'Canada','Ireland',0
'Canada','Netherlands',5
'Canada','UK,5
'Belgium','Netherlands',0
There is no certainty that the same payees exist for each payor (i.e. not
all countries have treaties with other all other countries)
I want to select all rows where the payee is in some array (e.g, in
('Netherlands','Ireland')) and the rate is not the same
In other words, in the sample above, I only want to return:
'Canada','Ireland',0
'Canada','Netherlands',5
The initial query to limit the rows to the specified payees is obvious, but
I can't get my mind around how to compare each set of rows where the payor
is the same country. Running select payor, payee, rate where payee in
('Netherlands','Ireland') will return 132 rows (66 pairs).
Any suggestions on how to compare the pairs would be appreciated.
Bryan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bryan.emrys@gmail.com
Subject: Re: SQL dealing with subquery
In-Reply-To: <eee4647d0801151004t288b0819ocbc0cae8e0df7f24@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox