Search Postgresql Archives

Re: Selecting top N percent of records.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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@xxxxxxxxxxxxxx)
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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux