简体   繁体   English

rownumber()函数对相邻单元格进行计数

[英]rownumber() function to count adjacent cells

I need to update contact person data using DTW (can't do directly with sql script). 我需要使用DTW更新联系人数据(不能直接使用sql脚本执行)。 'CardCode' is the key field. “ CardCode”是关键字段。 'CntctCode' is the record but you cannot update on the field. “ CntctCode”是记录,但是您不能在该字段上更新。 You must import use a number starting with 0 and increasing for each record. 您必须使用一个从0开始且每个记录递增的数字进行导入。 I want the query to add a field starting ay 0 and increasing for each new CardCode record. 我希望查询添加从0开始的字段,并为每个新的CardCode记录增加字段。

I have been successful with row_number() over order function but only for 1 CardCode record. 我已经成功地使用了row_number()命令功能,但是仅用于1个CardCode记录。 I need it to work on a larger set of CardCodes. 我需要它来处理更大的CardCode。

select  row_number() over (order by CntctCode) as PositionInTable
,       *
from OCPR



select  row_number() over (order by T0.CntctCode) as PositionInTable
,       *
from    OCPR T0 
    WHERE T0.CardCode = 'C00001'



PositionInTable CntctCode   CardCode
1   12101   C00001
2   12102   C00001
3   12103   C00001
4   12315   C00001
5   12696   C00001
6   13097   C00001
7   13098   C00001
8   13328   C00001
9   13408   C00001
10  13628   C00001
11  13661   C00001
12  13662   C00001
13  14634   C00001

you can use partition by 你可以使用分区

select  row_number() over (partition by CardCode order by CntctCode) as PositionInTable
,       *
from OCPR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM