Re: Selecting top N percent of records.

Поиск
Список
Период
Сортировка
От Peter Geoghegan
Тема Re: Selecting top N percent of records.
Дата
Msg-id AANLkTi=i9G+5aVqvfnbB2RKGL4Rtfnh_PRN_aZOCu2te@mail.gmail.com
обсуждение исходный текст
Ответ на Selecting top N percent of records.  (Tim Uckun <timuckun@gmail.com>)
Ответы Re: Selecting top N percent of records.  (Tim Uckun <timuckun@gmail.com>)
Список pgsql-general
On 18 October 2010 00:33, Tim Uckun <timuckun@gmail.com> wrote:
> Is there a way to select the top 10% of the values from a column?
>
> For example the top 10% best selling items where number of sales is a column.
>

That is a bit problematic because it necessitates knowing the number
of rows total, and slow counting is an idiosyncrasy of postgres.

http://wiki.postgresql.org/wiki/Slow_Counting

To get the top 10%:

SELECT * FROM table LIMIT(SELECT (COUNT(*) * 0.1)::integer FROM table)

--
Regards,
Peter Geoghegan

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

Предыдущее
От: Kynn Jones
Дата:
Сообщение: Re: Fastest way to check database's existence
Следующее
От: Tim Uckun
Дата:
Сообщение: Re: Selecting top N percent of records.