Re: Selecting top N percent of records.

Поиск
Список
Период
Сортировка
От Brent Wood
Тема Re: Selecting top N percent of records.
Дата
Msg-id 4CBC72640200007B00030A45@gwia.niwa.co.nz
обсуждение исходный текст
Ответ на Selecting top N percent of records.  (Tim Uckun <timuckun@gmail.com>)
Список pgsql-general
Something like this should work - (but is untested), and does require the extra subquery, so there may be a more efficient way?

However, off the top of my head:

select a,b,c
from table
where <where clause>
order by c desc
limit (select count(*)/10 from table where <same where clause>);


where c is the no of sales column




Brent Wood
DBA/GIS consultant
NIWA, Wellington
New Zealand

>>> Tim Uckun <timuckun@gmail.com> 10/18/10 3:40 PM >>>
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.

Thanks.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.

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

Предыдущее
От: Greg Smith
Дата:
Сообщение: Re: installing from source in Windows
Следующее
От: guti deng
Дата:
Сообщение: How to track error messages come from plpy.execute?