清理oracle数据库下的数据重复,并保留其一

select * from b2bx where
create_date in
       (to_date('2017-12-11 08:22:16', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:17', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:18', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:19', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:20', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:21', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:22', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:23', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11  08:32:55', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:32:56', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11  08:32:57', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:32:58', 'yyyy-mm-dd hh24:mi:ss'),
          to_date('2017-12-11 08:32:59', 'yyyy-mm-dd hh24:mi:ss'),  
         to_date('2017-12-11 08:33:00', 'yyyy-mm-dd hh24:mi:ss')
          )and create_user='admin'
          -- 141 - 94 = ?  刚好47     重复  3次    94/2 = ?   47       、、   此时重复2次   然后再次执行一次    就剩余47条    OK

select cc.id from (
select a.rowid,a.* from b2bx a
where a.rowid =
(
select max(b.rowid) from b2bx b
where a.lotn = b.lotn and
create_date in
       (to_date('2017-12-11 08:22:16', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:17', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:18', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:19', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:20', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:21', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:22', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:23', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11  08:32:55', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:32:56', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11  08:32:57', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:32:58', 'yyyy-mm-dd hh24:mi:ss'),
          to_date('2017-12-11 08:32:59', 'yyyy-mm-dd hh24:mi:ss'),  
         to_date('2017-12-11 08:33:00', 'yyyy-mm-dd hh24:mi:ss')
          )and create_user='admin'
)
) cc

select count(*) from b2bx ;  -- 2962982   临时   删除47 怎么只有40条
select count(*) from b2bx -- 2962952   临时   删除47 怎么只有40条

select count(*) from b2bx   -- 2962952   临时   删除47 怎么只有40条
--    2962952 -2962905 = ?   47 ==   刚好   47    

delete from b2bx where id in (
select cc.id from (

select a.rowid,a.* from b2bx a
where a.rowid =
(
select max(b.rowid) from b2bx b
where a.lotn = b.lotn and
create_date in
       (to_date('2017-12-11 08:22:16', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:17', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:18', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:19', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:20', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:21', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:22', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:22:23', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11  08:32:55', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:32:56', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11  08:32:57', 'yyyy-mm-dd hh24:mi:ss'),
         to_date('2017-12-11 08:32:58', 'yyyy-mm-dd hh24:mi:ss'),
          to_date('2017-12-11 08:32:59', 'yyyy-mm-dd hh24:mi:ss'),  
         to_date('2017-12-11 08:33:00', 'yyyy-mm-dd hh24:mi:ss')
          )and create_user='admin'
)
) cc
)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值