pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rodrigo De León <rdeleonp@gmail.com>
To: Bryce Nesbitt <bryce1@obviously.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Getting pk of the most recent row, in a group by
Date: Mon, 13 Aug 2007 15:16:49 -0500
Message-ID: <a55915760708131316t4ae9e506i3980e4ad87a8268c@mail.gmail.com> (raw)
In-Reply-To: <46C0B994.6090906@obviously.com>
References: <46C0B994.6090906@obviously.com>

On 8/13/07, Bryce Nesbitt <bryce1@obviously.com> wrote:
> In the second example, is it possible to get the primary key of the row
> with the minimum expires time?

SELECT   TYPE, MIN(expires), COUNT(*)
       , (SELECT MIN(coupon_id)
            FROM coupon
           WHERE expires = MIN(c.expires)) AS coupon_id
    FROM coupon c
GROUP BY TYPE;



view thread (4+ messages)  latest in thread

Message-ID: <a55915760708131316t4ae9e506i3980e4ad87a8268c@mail.gmail.com>
Permalink:  ../a55915760708131316t4ae9e506i3980e4ad87a8268c@mail.gmail.com/
Also on:    postgresql.org/message-id/a55915760708131316t4ae9e506i3980e4ad87a8268c@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, bryce1@obviously.com
  Subject: Re: Getting pk of the most recent row, in a group by
  In-Reply-To: <a55915760708131316t4ae9e506i3980e4ad87a8268c@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