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!

How to get top 5% of account

Status
Not open for further replies.

natncm70

MIS
Jan 16, 2002
66
IN
Hello,
I need to take TOP 5% of account, based on Account_balance. How should i take?
Pl. help me.
Regards
 
select account_balance,rank(account_balance)
from accounttable
cross join (select count(*) from accounttable) as tmp(nbr)
qualify rank(account_balance)<tmp.nbr*0.05
 
V2R3+:
select account_balance
from accounttable
qualify
quantile(100, account_balance desc) <= 5

V2R4.1+:
select account_balance
from accounttable
qualify
percent_rank() over (order by account_balance desc) <= 0.05

Percent_rank is SQL:1999 whereas quantile is a Teradata extension.
Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top