zoukankan      html  css  js  c++  java
  • oracle删除一个表内的重复数据,

    查询以及删除一个数据库表内的重复数据。

    1.查询表中的多余的重复记录,重复记录是根据单个字段来判断的。

    select * from biao where id in (select id from biao group by id having count(id) >1 )

    2.删除表中的多余的重复记录,重复记录是根据(id)来判断,只留rowid 最小值。

     delete from  biao where id  in   ( select  id from biao group by id having count(id) )  and  rowid not in  ( select  min(rowid) from  biao group by id having count(id)>1 )

    delete from xuesheng
    where T_NAME in
    (select T_NAME
    from xuesheng
    group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
    having count(*) > 1) --重复数据
    and rowid not in
    (select max(rowid)
    from xuesheng
    group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
    having count(*) > 1) --保留一条重复数据

    3.删除表中重复的记录(多个字段),

    delete from xuesheng
    where T_NAME in
    (select T_NAME
    from xuesheng
    group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
    having count(*) > 1) --不保留重复数据

    来自:https://www.cnblogs.com/252e/archive/2012/09/13/2682817.html

  • 相关阅读:
    各种知识点
    链表
    滑动窗口
    数组

    【转】无重复字符的最长子串
    【转】荷兰国旗问题 三指针排序
    【转】回溯思想团灭排列、组合、子集问题
    【LeetCode】45. 跳跃游戏 II
    动态分配内存初始化二维数组
  • 原文地址:https://www.cnblogs.com/brianlai/p/10302654.html
Copyright © 2011-2022 走看看