Listing 1: Finding the Top 15 Percent of Customers
select * from
(select customer_id as cust_id, sum(sales_amt) as
cust_sales, round(100 * CUME_DIST() over(order by
sum(sales_amt) asc)) as cust_percentile
from sales group by customer_id)
where cust_percentile > 85
order by cust_percentile desc;
CUST_ID CUST_SALES CUST_PERCENTILE
------------ ----------------- ------------------------
133461 2175523 100
270570 1805256 99
160160 1801329 98
...... ....... ..
...... ....... ..
133508 1124910 86
|