Re: fetch first rows of grouped data

Поиск
Список
Период
Сортировка
От D'Arcy J.M. Cain
Тема Re: fetch first rows of grouped data
Дата
Msg-id 20070827141552.21ec3a54.darcy@druid.net
обсуждение исходный текст
Ответ на Re: fetch first rows of grouped data  (Joel Richard <postgres@joelrichard.com>)
Список pgsql-sql
On Mon, 27 Aug 2007 13:34:09 -0400
Joel Richard <postgres@joelrichard.com> wrote:
> 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.

Yes, you are correct.  My mistake.

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

Well, I can think of an SQL only method involving a temporary table but
it would not be a single query:
- Select into temp table where date is max.- Select from temp table union with main table where date is max and
is not in temp table.

-- 
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.


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

Предыдущее
От: Michael Glaesemann
Дата:
Сообщение: Re: fetch first rows of grouped data
Следующее
От: Michael Glaesemann
Дата:
Сообщение: Re: fetch first rows of grouped data