CREATE TABLE customers
( customer_id number(10) not null,
customer_name varchar2(50) not null
);
INSERT INTO customers VALUES(22,'W');
INSERT INTO customers VALUES(22,'W');
INSERT INTO customers VALUES(20,'Q');
INSERT INTO customers VALUES(20,'Q');
COMMIT;
现在我想按客户名称
获得与我的分区相对应的不同排名SELECT DENSE_RANK() OVER(PARTITION BY customer_name ORDER BY CUSTOMER_ID) , CUSTOMER_ID FROM CUSTOMERS;
输出中:
1 20
1 20
1 22
1 22
预期产出:
1 20
1 20
2 22
2 22
答案 0 :(得分:0)
使用以下查询
SELECT
DENSE_RANK() OVER(ORDER BY CUSTOMER_ID) ,
CUSTOMER_ID
FROM CUSTOMERS;
删除分区BY by子句,因为如果你使用partition by子句,它将根据名称划分结果。