Oracle如何根据多个数据库列和条件删除重复项(Oracle How delete duplicates based on multiples database columns and conditions)
我有一个非常庞大的表,其中包含从多个系统收集的数据。 我现在必须根据条件和多列删除重复记录。
这是一个例子:
+---------------+-------------+------+-----+-------- | System ID | Debt Num | Exp Dt | Account NO | +---------------+-------------+------+-----+--------- | pay | 2222 | 0114 | 111 | | pay | 2222 | 0214 | 111 | | Online | 2222 | 0214 | 111 | | Online | 3333 | 0115 | 222 | | Online | 3333 | 0116 | 222 | | ERP | 2222 | 0214 | 111 | | ERP | 4444 | 0114 | 333 | +---------------+-------------+------+-----+--------
从以上数据中删除满足以下条件的重复项。
- 通过debit num,exp dt,account-no删除重复的行组,并使用max(exp dt)保留一条记录。
- 要保留的记录基于
System ID
的优先级。 1)支付2)在线和3)ERP。 在上面的帐户111中,我们有来自所有三个系统的记录,并且借记卡的max(exp dt)是所有三个系统中的0214。 只保留Pay
with exp dt = 0214的记录,并删除其余部分。- 如上面的帐户222示例,我们没有来自pay的记录,因此优先考虑系统Online和ERP,其中应保留max(exp dt)。
我尝试过在线发现的多个查询,例如group by,row_number over,但所有只满足一个条件。
感谢您的帮助,提出您的想法和建议。
EDIT
:戈登的查询工作正常,符合我的要求,但是当我在包含540K行的分段上运行相同时,它出错了ORA-00600内部错误。I have a very huge table with data collected from multiple systems. I now have to delete duplicate records based on conditions and multiple columns.
Here is an example:
+---------------+-------------+------+-----+-------- | System ID | Debt Num | Exp Dt | Account NO | +---------------+-------------+------+-----+--------- | pay | 2222 | 0114 | 111 | | pay | 2222 | 0214 | 111 | | Online | 2222 | 0214 | 111 | | Online | 3333 | 0115 | 222 | | Online | 3333 | 0116 | 222 | | ERP | 2222 | 0214 | 111 | | ERP | 4444 | 0114 | 333 | +---------------+-------------+------+-----+--------
From the above data , delete the duplicates with the following conditions satisfied.
- Delete the duplicate rows group by debit num , exp dt , account-no and keep one record with max(exp dt).
- Records to be retained is based of priority to
System ID
. 1) pay 2) Online and 3) ERP. In the above for the account 111 we have records from all three systems and max(exp dt) of the debit card is 0214 of all three system. Only the record fromPay
with exp dt=0214 should be retained and rest should be deleted.- As above example for account 222 , we dont have records from pay and hence give priority to system Online and the ERP out of which the max(exp dt) should be retained.
I have tried multiple queries found online , like group by, row_number over but all fulfill just one condition.
Appreciate your help to contribute your thoughts and suggestions.
EDIT
: Gordon's query works fine and fits my requirements, however when I ran the same on staging which contains 540K rows, it error out ORA-00600 Internal error.
原文:https://stackoverflow.com/questions/21354812
最满意答案
我用的输入法是QQ拼音,你按V1后就可以进入符号输入里面,寻找自己喜欢的符号。
希望对楼主有所帮助!
其他回答
智能abc输入法有这样的功能 §v1就可以弹出选择列表 v2 v3 v4 v5 v6 v7 v8 v9 你都可以44 看到很多东西了吧
qq拼音 v1~v9都有
相关问答
更多-
Linux中各种特殊符号的含义(求助)[2023-08-10]
那是shell的语法,找相关的变量教程看看吧 -
xml 特殊符号问题[2022-10-30]
应该可以的,双引号没什么影响吧。 你一定要有根目录: 例如: "aaaaa" "bbbbb" 像这样是可以的。 -
怎样打多个特殊符号[2023-09-23]
我用的输入法是QQ拼音,你按V1后就可以进入符号输入里面,寻找自己喜欢的符号。 希望对楼主有所帮助! -
特殊符号™ 什么意思啊?[2022-07-05]
在中国,商标上的TM也有其特殊含义,其实TM标志并非对商标起到保护作用,它与R不同,TM表示的是该商标已经向国家商标局提出申请,并且国家商标局也已经下发了《受理通知书》,进入了异议期,这样就可以防止其他人提出重复申请,也表示现有商标持有人有优先使用权。 用圆圈R,是“注册商标”的标记,意思是该商标已在国家商标局进行注册申请并已经商标局审查通过,成为注册商标。圆圈里的R是英文register注册的开头字母。 注册商标具有排他性、独占性、唯一性等特点,属于注册商标所有人所独占,受法律保护,任何企业或个人未经注册 ... -
VB6.0 中 CHR() 函数如何使用? 还有特殊符号的 ASCII 码是多少? 如回车 空格[2022-11-17]
chr()函数的作用是讲一个ascii码转化为相应的字符.比如 chr(65)的返回值就是字符 A,至于ASCII码表 ,可以给你一个网址,上面有很详细的讲解`我就不复制粘贴了 http://baike.baidu.com/view/15482.htm -
您可以根据您的要求使用此正则表达式: \A(?=(?:[^a-zA-Z]*[a-zA-Z]){2})[a-zA-Z0-9\s&-]+\z RegEx分手: \A :开始 (?=(?:[^a-zA-Z]*[a-zA-Z]){2}) :断言断言我们输入中至少有2个字母 [a-zA-Z0-9\s&-]+ :匹配字母数字字符或空格或&或- \z :结束 RegEx演示 You can use this regex for your requirement: \A(?=(?:[^a-zA-Z]*[a-zA-Z]){ ...
-
在HTML中添加特殊符号(Adding special symbols into HTML)[2022-05-29]
两者都有其优点和缺点。 没有一个强有力的最佳实践。 使用文字字符: 更容易阅读 不要求开发人员记住字符引用代码 需要更少的字节/字符通过网络发送(或存储在数据库中,这可能更重要)。 使用字符参考: 可能更容易键入(取决于开发人员的键盘) 不受字符编码错误的影响 Both have their pros and cons. There isn't a strongly established best practice. Using a literal character: Is easier to read ... -
那么使用jquery和这个: $("#textField").html(' ').text() 或者更一般: $(element).html(encodedString).text() What about using jquery and this: $("#textField").html(' ').text() Or in more general: $(element).html(encodedString).text()
-
一个经典的问题,通常在正则表达式的帮助下解决。 var myString = "London"; if (myString.match(/^[a-zA-Z_]+$/)) { // Success } 如果要允许空格,例如纽约,请将模式更改为/^[a-zA-Z_\s]+$/ 。 A classic problem that's usually solved with the help of regular expressions. var myString = "London"; if (myStr ...
-
“'的特殊符号(special symbol for " ')[2022-09-23]
如何在不使用像”这样的特殊符号的情况下解决此问题 你不这样做,虽然在这种情况下rdquo是错误的字符引用。 在将文本插入HTML文档之前,通过htmlspecialchars()将文本htmlspecialchars()为HTML。 how solve this problem without using special symbols like ” You don' ...