计算没有任何订单价值的排名模式

时间:2016-05-16 10:47:32

标签: sql

我的数据是这样的 -

enter image description here

您可以查看3列, jil_equipment_id,req_group,操作数。 基于这3列,我必须生成一个新的“ Patern ”列。

patern列是patern,从2开始,对于 jil_equipment_id,req_group,operand的每个重复组合,增加1。

最终数据将如下所示。 enter image description here

请建议我任何可行的方法。我无法在此使用RANK()/ DENSE_RANK()函数。

2 个答案:

答案 0 :(得分:1)

您可以使用row_number()。您也希望使用partition by

select t.*,
       (1 + row_number() over (partition by jil_equipment_id, req_group, operand
                               order by content_id
                              )
       ) as pattern
from t;

答案 1 :(得分:0)

select *,Row_Number() over(partition by jil_equipment_id,req_group,operand   order by  jil_equipment_id,req_group,operand) + 1 as pattern
from tab

您可以使用row_number()功能。

相关问题