首页 \ 问答 \ Oracle如何根据多个数据库列和条件删除重复项(Oracle How delete duplicates based on multiples database columns and conditions)

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 from Pay 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
更新时间:2022-06-13 22:06

最满意答案

我用的输入法是QQ拼音,你按V1后就可以进入符号输入里面,寻找自己喜欢的符号。

希望对楼主有所帮助!

其他回答

智能abc输入法有这样的功能
§v1就可以弹出选择列表
v2
v3
v4
v5
v6
v7
v8
v9
你都可以44 看到很多东西了吧
qq拼音  v1~v9都有

相关问答

更多
  • 那是shell的语法,找相关的变量教程看看吧
  • 应该可以的,双引号没什么影响吧。 你一定要有根目录: 例如: "aaaaa" "bbbbb" 像这样是可以的。
  • 我用的输入法是QQ拼音,你按V1后就可以进入符号输入里面,寻找自己喜欢的符号。 希望对楼主有所帮助!
  • 在中国,商标上的TM也有其特殊含义,其实TM标志并非对商标起到保护作用,它与R不同,TM表示的是该商标已经向国家商标局提出申请,并且国家商标局也已经下发了《受理通知书》,进入了异议期,这样就可以防止其他人提出重复申请,也表示现有商标持有人有优先使用权。 用圆圈R,是“注册商标”的标记,意思是该商标已在国家商标局进行注册申请并已经商标局审查通过,成为注册商标。圆圈里的R是英文register注册的开头字母。 注册商标具有排他性、独占性、唯一性等特点,属于注册商标所有人所独占,受法律保护,任何企业或个人未经注册 ...
  • 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]){ ...
  • 两者都有其优点和缺点。 没有一个强有力的最佳实践。 使用文字字符: 更容易阅读 不要求开发人员记住字符引用代码 需要更少的字节/字符通过网络发送(或存储在数据库中,这可能更重要)。 使用字符参考: 可能更容易键入(取决于开发人员的键盘) 不受字符编码错误的影响 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 ...
  • 如何在不使用像”这样的特殊符号的情况下解决此问题 你不这样做,虽然在这种情况下rdquo是错误的字符引用。 在将文本插入HTML文档之前,通过htmlspecialchars()将文本htmlspecialchars()为HTML。 how solve this problem without using special symbols like ” You don' ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)