From: | "Brent Wood" <b(dot)wood(at)niwa(dot)co(dot)nz> |
---|---|
To: | <timuckun(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Selecting top N percent of records. |
Date: | 2010-10-18 03:14:24 |
Message-ID: | 4CBC72640200007B00030A45@gwia.niwa.co.nz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
order by c desc
limit (select count(*)/10 from table where );
where c is the no of sales column
Brent Wood
DBA/GIS consultant
NIWA, Wellington
New Zealand
>>> Tim Uckun 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(at)postgresql(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Turner, John J | 2010-10-18 03:28:33 | Re: installing from source in Windows |
Previous Message | Greg Smith | 2010-10-18 02:46:39 | Re: installing from source in Windows |