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

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: <a55915760801151240w61aa3520g548eff734190061e@mail.gmail.com>
Permalink:  ../a55915760801151240w61aa3520g548eff734190061e@mail.gmail.com/
Also on:    postgresql.org/message-id/a55915760801151240w61aa3520g548eff734190061e@mail.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: rdeleonp@gmail.com, bryan.emrys@gmail.com
  Subject: Re: SQL dealing with subquery
  In-Reply-To: <a55915760801151240w61aa3520g548eff734190061e@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