I am stuck with the row number over one column group by another column.
我被另一列的一个列组的行号卡住了。
This is my data set
这是我的数据集
PR_Cmd PR_Expd
--------------------------
CVP909104 LVP1ET03904305
CVP909105 LVP1ET03904306
CVP909105 LVP1ET03904306
CVP909105 LVP1ET03904306
CVP909105 LVP1ET03904306
CVP909105 LVP1ET03904306
CVP909105 LVP1ET03904307
CVP909106 LVP1ET03904308
What I want to get :
我想得到什么:
PR_Cmd PR_Expd Expd_Number
-------------------------------------------
CVP909104 LVP1ET03904305 1
CVP909105 LVP1ET03904306 1
CVP909105 LVP1ET03904306 1
CVP909105 LVP1ET03904306 2
CVP909105 LVP1ET03904307 3
CVP909106 LVP1ET03904308 1
1 个解决方案
#1
1
What you seem to want is dense_rank()
.
你似乎想要的是dense_rank()。
dense_rank() over (partition by pr_cmd order by pr_expd)
This will restart the numbering for each value of pr_cmd
.
这将重新启动pr_cmd的每个值的编号。
#1
1
What you seem to want is dense_rank()
.
你似乎想要的是dense_rank()。
dense_rank() over (partition by pr_cmd order by pr_expd)
This will restart the numbering for each value of pr_cmd
.
这将重新启动pr_cmd的每个值的编号。