Re: fetch first rows of grouped data

Поиск
Список
Период
Сортировка
От Joel Richard
Тема Re: fetch first rows of grouped data
Дата
Msg-id 4CB5D209-C0CC-466E-A967-E766D6AD799B@joelrichard.com
обсуждение исходный текст
Ответ на Re: fetch first rows of grouped data  ("D'Arcy J.M. Cain" <darcy@druid.net>)
Ответы Re: fetch first rows of grouped data  (Michael Glaesemann <grzm@seespotcode.net>)
Re: fetch first rows of grouped data  ("D'Arcy J.M. Cain" <darcy@druid.net>)
Список pgsql-sql
That's what I thought at first, but this is not the case. She's  
looking for the first two dates in -each- city in the table. I  
initially thought that this could be accomplished with GROUP BY and  
LIMIT, but GROUP BY can only give you the first date for each city,  
not the first two dates for each city.

So far, I haven't come up with any clever ideas. I'm not sure this  
can be done in SQL.

--Joel


On Aug 27, 2007, at 12:51 PM, D'Arcy J.M. Cain wrote:

> On Mon, 27 Aug 2007 18:36:47 +0200
> Claudia Kosny <ckosny@gmx.net> wrote:
>> I have a list of events that take place in a certain city at a  
>> certain
>> date. Now I would like to have the first two (ordered by date) events
>> for each city.
>>
>> Is there a way to do this with one query?
>> I am using PostgreSQL 7.4.
>
> I believe you are looking for the LIMIT keyword.  Check the docs on  
> the
> web site.
>
> -- 
> D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three  
> wolves
> http://www.druid.net/darcy/                |  and a sheep voting on
> +1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster



В списке pgsql-sql по дате отправления:

Предыдущее
От: "D'Arcy J.M. Cain"
Дата:
Сообщение: Re: fetch first rows of grouped data
Следующее
От: Michael Glaesemann
Дата:
Сообщение: Re: fetch first rows of grouped data