Skip site navigation (1) Skip section navigation (2)

Re: SQL dealing with subquery

From: Bryan Emrys <bryan(dot)emrys(at)gmail(dot)com>
To: "Rodrigo E(dot) De León Plicet" <rdeleonp(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL dealing with subquery
Date: 2008-01-16 15:54:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
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.


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(dot)emrys(at)gmail(dot)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');

In response to


pgsql-sql by date

Next:From: Scott MarloweDate: 2008-01-16 16:15:48
Subject: Re: Update PK Violation
Previous:From: Achilleas MantziosDate: 2008-01-16 14:30:14
Subject: Re: Update PK Violation

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group