pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryan Emrys <bryan.emrys@gmail.com>
To: Rodrigo E. De León Plicet <rdeleonp@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL dealing with subquery
Date: Wed, 16 Jan 2008 07:54:41 -0800
Message-ID: <200801160754.41769.bryan.emrys@gmail.com> (raw)
In-Reply-To: <a55915760801151240w61aa3520g548eff734190061e@mail.gmail.com>
References: <eee4647d0801151004t288b0819ocbc0cae8e0df7f24@mail.gmail.com>
	<a55915760801151240w61aa3520g548eff734190061e@mail.gmail.com>

Thanks. It throws off a few extra countries where there is only one treaty, but those are 
few enough that I can handle them manually.

I thought the solution was also going to give me insight into how to select just the lowest 
rate from each couple, (i.e. for each payor, who is the lowest rate payee) but it looks like 
I'll have find some time to think about that later (I've also got to think about what to do in tie situations.).

Again, thanks.

Bryan

On Tuesday 15 January 2008 12:40:13 pm Rodrigo E. De León Plicet wrote:
> On Jan 15, 2008 1:04 PM, Bryan Emrys <bryan.emrys@gmail.com> wrote:
> > In other words, in the sample above, I only want to return:
> > 'Canada','Ireland',0
> > 'Canada','Netherlands',5
> 
> Try (untested):
> 
> SELECT t2.*
> FROM   (SELECT   payor
>         FROM     treaty_rates
>         WHERE    payee IN ('Netherlands', 'Ireland')
>         GROUP BY payor
>         HAVING   MIN (rate) != MAX (rate)) t1
>        JOIN
>        treaty_rates t2 ON t1.payor = t2.payor
> WHERE  t2.payee IN ('Netherlands', 'Ireland');
> 





view thread (4+ messages)  latest in thread

Message-ID: <200801160754.41769.bryan.emrys@gmail.com>
Permalink:  ../200801160754.41769.bryan.emrys@gmail.com/
Also on:    postgresql.org/message-id/200801160754.41769.bryan.emrys@gmail.com

 · 

reply

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, rdeleonp@gmail.com
  Subject: Re: SQL dealing with subquery
  In-Reply-To: <200801160754.41769.bryan.emrys@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