我的简单查询返回如下数据:
SELECT column1, column2 FROM table1
COLUMN1 COLUMN2
------- -------
CA A
CA B
CB C
CB D
我想用这些值返回column3(对于相同的COLUMN1值,我想返回相同的序列号):
COLUMN3
-------
1
1
2
2
答案 0 :(得分:2)
您可以使用analytic
函数DENSE_RANK
。
SELECT column1, column2, DENSE_RANK() OVER(ORDER BY column1) as "column3" FROM table1
请参阅以下示例 - oracle-base.com/articles/misc/rank-dense-rank-first-last-analytic-functions.php#dense_rank
答案 1 :(得分:2)
尝试此查询,
Select column1, column2,
dense_rank() over (order by column1) as column3
from table1;