【发布时间】:2015-10-13 18:25:09
【问题描述】:
在我的数据中创建正确的分区时遇到了一些问题。这是我的数据的示例,并带有所需的输出:
customer contract type1 type2 partition
100 1 A A 1
100 2 A A 1
100 3 A B 2
100 4 A B 2
100 5 A B 2
100 6 A A 3
100 7 A A 3
100 8 C A 4
100 9 C A 4
我要构造的变量是最后一个,称为分区。我现在遇到的问题是,当使用dense_rank 时,合同 1 和 2 与合同 6 和 7 组合在一起:
select
t1.*
, dense_rank() over (order by customer, type1, type2) as partition
from table1 t1
我可以使用什么来生成所需的输出(在相当大的数据集上)?
【问题讨论】:
-
试试
dense_rank() over (partition by customer,contract,type1,type2 order by customer, type1, type2) as partition -
@vkp 为每一行分配数字 1
标签: sql oracle aggregation