【1】测试环境:
Name Null? Type
----------------------------------------- -------- ----------------------------
REGION_ID NUMBER(2)
CUSTOMER_ID NUMBER(2)
CUSTOMER_SALES NUMBER
SQL> select region_id, customer_id, sum(customer_sales) total,
rank() over(order by sum(customer_sales) desc) rank,
dense_rank() over(order by sum(customer_sales) desc) dense_rank,
row_number() over(order by sum(customer_sales) desc) row_number
from user_order
group by region_id, customer_id;
SQL> select region_id, customer_id,
sum(customer_sales) total,
rank() over(partition by region_id
order by sum(customer_sales) desc) rank,
dense_rank() over(partition by region_id
order by sum(customer_sales) desc) dense_rank,
row_number() over(partition by region_id
order by sum(customer_sales) desc) row_number
from user_order
group by region_id, customer_id;