Group by and lmit

Поиск
Список
Период
Сортировка
От Bill Reynolds
Тема Group by and lmit
Дата
Msg-id 7C0800F63CCF4149AC0FC5EE2A04122607BA95AF@sr002-2k3exc.ateb.com
обсуждение исходный текст
Ответ на Re: Replication  ("Jonathan Tripathy" <jonnyt@abpni.co.uk>)
Ответы Re: Group by and lmit  (Filip Rembiałkowski <filip.rembialkowski@gmail.com>)
Список pgsql-general

Hey Folks – have a coded myself into a corner yet?

 

I have a situation with a select count / group by / order by query that I need to limit each group to 500 entries.   Not seeing a way to do this in a single query, do I need to use multiple queries?

Group x has about 200 entries in it; group y has about 5-8k per x.

 

select x, y, count(*) as counter from mytable

 group by x, y

 order by x, counter, y

 

 

   I only want the first 500 for each x.

 

   Any tips or tricks someone might know would be appreciated.

 

   I’m using postgres 8.3.7.

 

   Thanks, Bill

 

 

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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: 8.4 Data Not Compatible with 9.0.1 Upgrade?
Следующее
От: Dimitri Fontaine
Дата:
Сообщение: Re: pg_get_procdef ?