rank and percent_rank : PERCENT_RANK « Analytical Functions « Oracle PL / SQL






rank and percent_rank

  

SQL> CREATE TABLE sales(
  2    product_id            NUMBER(6),
  3    cid           NUMBER,
  4    time_id               DATE,
  5    sold         NUMBER(3),
  6    amount                NUMBER(10,2),
  7    cost                  NUMBER(10,2)
  8  );

Table created.

SQL> select product_id,sum(sold),rank () over (order by sum(sold) desc) as rank,
  2         percent_rank () over (order by sum(sold) asc) as percent_rank
  3  from sales
  4  where to_char(time_id, 'yyyy-mm') = '2001-06'
  5  group by product_id
  6  order by sum(sold) desc;

no rows selected

SQL>
SQL> drop table sales;

Table dropped.

   
    
  








Related examples in the same category

1.PERCENT_RANK(): calculate the percent rank of a value relative to a group of values
2.Rank, Percent_Rank, and Cume_Dist, NTILE
3.Percent_rank (PR) = (Rank-1)/(Number of rows-1)