包含重复项的表需要批量更新
我有一个包含这样的数据的表
transactionCode | column2 | column3 | column4 | wCode | aCode | column7 | column8 | column9 | column10 | liNumber |
---|---|---|---|---|---|---|---|---|---|---|
7938636 | 2 | INVOICE | NULL | 1 | MZ690577 | 2021-01-28 | NULL | 2021-01-28 | 1 | 6 |
7938636 | 2 | INVOICE | NULL | 1 | MD191807 | 2021-01-28 | 空 | 2021-01-28 | 1 | 4 |
7938631 | 2 | 发票 | 空 | 1 | MZ320771 | 2021-01-28 | 空 | 2021-01-28 | 1 | 1 |
7938631 | 2 | 发票 | 空 | 1 | 7803A112 | 2021-01-28 | 空 | 2021-01-28 | 4 | 2 |
7938576 | 2 | 发票 | 空 | 1 | 8201A216 | 2021-01-29 | 空 | 2021-01-29 | 1 | 1 |
7938598 | 2 | 发票 | 空 | 1 | SP046271 | 2021-01-29 | 空 | 2021-01-29 | 1 | 14 |
我也有一个这样的脚本,它为我找到重复项
WITH cte
AS (SELECT transactionid,
aCode,
liNumber,
wCode,
RN = Row_number()
OVER(
partition BY
transactionid,
aCode,
liNumber,
wCode
ORDER BY
transactionid)
FROM duplicates)
SELECT * FROM cte
WHERE RN > 1;
运行该脚本时,显示的数据采用这样的格式..
transactionID | aCode | liNumber | wCode | RN |
---|---|---|---|---|
1012751 | DISCOUNT | 9 | 1 | 2 |
然后我可以在重复项表中搜索该 aCode 或 transactionID 以查看有多少个。到目前为止,在我的重复表中,该脚本总共返回 34,791 行。请注意,具有相同 liNumber 的项目需要更改。
我的问题是,如何处理如此大量的数据?
例如,
事务 7938636 可能有 5 行。全部具有相同的 wCode 和相同的 aCode 但 liNumber 会以 1、2、3、4 等增量递增。当一行有相同的liNumber时;说 1 那么它被归类为重复项。然后,我需要更新该重复行以继续增量(从 6、7、8 等)。
这有道理吗?
I've got a table containing data like this
transactionCode | column2 | column3 | column4 | wCode | aCode | column7 | column8 | column9 | column10 | liNumber |
---|---|---|---|---|---|---|---|---|---|---|
7938636 | 2 | INVOICE | NULL | 1 | MZ690577 | 2021-01-28 | NULL | 2021-01-28 | 1 | 6 |
7938636 | 2 | INVOICE | NULL | 1 | MD191807 | 2021-01-28 | NULL | 2021-01-28 | 1 | 4 |
7938631 | 2 | INVOICE | NULL | 1 | MZ320771 | 2021-01-28 | NULL | 2021-01-28 | 1 | 1 |
7938631 | 2 | INVOICE | NULL | 1 | 7803A112 | 2021-01-28 | NULL | 2021-01-28 | 4 | 2 |
7938576 | 2 | INVOICE | NULL | 1 | 8201A216 | 2021-01-29 | NULL | 2021-01-29 | 1 | 1 |
7938598 | 2 | INVOICE | NULL | 1 | SP046271 | 2021-01-29 | NULL | 2021-01-29 | 1 | 14 |
I've also got a script like this which finds the duplicates for me
WITH cte
AS (SELECT transactionid,
aCode,
liNumber,
wCode,
RN = Row_number()
OVER(
partition BY
transactionid,
aCode,
liNumber,
wCode
ORDER BY
transactionid)
FROM duplicates)
SELECT * FROM cte
WHERE RN > 1;
When running that script the data shown is in a format like this..
transactionID | aCode | liNumber | wCode | RN |
---|---|---|---|---|
1012751 | DISCOUNT | 9 | 1 | 2 |
I can then search for that aCode or transactionID in the duplicates table to see how many there are. So far in my duplicates table, that script returns a total of 34,791 rows. Note, items that have the same liNumber needs to be changed.
My ask is, how do I go about doing this with this large amount of data?
For example,
Transaction 7938636 might have 5 rows. All with the same wCode and the same aCode BUT the liNumber goes up in increments like 1, 2, 3, 4 ect. When a row has the same liNumber; say 1 then that is classed as a duplicate. I then need to update that duplicate row to continue the increments, from 6, 7 , 8 ect.
Does this make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 liNumber 不是相同的序列(如(1,2,3,4...等)),因此您可以通过将 liNumber 的最大值与相应的行号相加来更新重复项,从而采用解决方法,如下所示。
注意:这只是一个示例数据,我没有考虑您的表格的全部内容。
Since the liNumber is not of identical sequence like (1,2,3,4...and so on) you can go with a workaround by updating the duplicates by adding the max of the liNumber with the corresponding rownumber as below.
Note: This is just a sample data and I did not consider your table to its entirety.