Re: fetch first rows of grouped data

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: Joel Richard <postgres(at)joelrichard(dot)com>, "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>, Claudia Kosny <ckosny(at)gmx(dot)net>, sql pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: fetch first rows of grouped data
Date: 2007-08-27 18:20:18
Message-ID: 56BD71D2-D761-4A80-9B3B-40CD7BF4BE8A@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Aug 27, 2007, at 13:12 , Michael Glaesemann wrote:

> select city, event, event_date, (
> select count(event)
> from events i
> where i.city = o.city
> and i.event_date < o.event_date
> and event_date > current_date -- make sure they're future
> events

This should be i.event_date > current_date to be explicit.

> ) as nearness_rank
> from events o
> where event_date > current_date -- make sure they're future events
> having nearness_rank <= 1;

Michael Glaesemann
grzm seespotcode net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Kristo Kaiv 2007-08-27 19:02:27 Re: [GENERAL] table column vs. out param [1:0]
Previous Message D'Arcy J.M. Cain 2007-08-27 18:15:52 Re: fetch first rows of grouped data