0
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
4

1 回答 1

1

使用以下查询

SELECT 
DENSE_RANK() OVER(ORDER BY CUSTOMER_ID) , 
CUSTOMER_ID 
FROM CUSTOMERS;

删除partition BY by 子句,因为如果您使用 partition by 子句,它将根据名称划分结果。

于 2015-03-30T07:16:56.977 回答