Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top 20 % 2

Status
Not open for further replies.

A11AR

Programmer
Oct 10, 2006
1
US
Hi all,

Can any one give me a breif idea that how to calculate top 20 % of the values.

I have stores which has got sales per year and i would like to get only top 20 % of the stores.

I would greatly apreciate the help

Thanks a lot
 
To get the TOP 20% of rows according to your WHERE clause it is

SELECT TOP 20 PERCENT stores

Just new to TD but I think this should give you what your after
 
select *
from tab
qualify
percent_rank() over (order by sales desc) <= 0.2

Easy to enhance with PARTITION BY, e.g.
percent_rank() over (order by sales desc partition by year) <= 0.2

to get top 20% per year...

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top