zoukankan      html  css  js  c++  java
  • sql查询重复记录、删除重复记录方法大全

    1.查询重复记录单字段

    select * from tbl a where  exists(select 1 from  tbl b where a.username=b.username group by username  having count(*) > 1)

    2.查询重复次数

    select clistname,count(clistname) from clalist  group by clistname having count(*)>1

    3.删除重复记录,留有rowid最小的记录

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

    4.查询重复记录,多字段

    select *
    from clalist a where exists
    (

    select 1 from clalist b
    where a.ClalistID=b.ClalistID and a.SchSNo=b.SchSNo
    group by ClalistID,SchSNo having count(*) > 1

    )
    order by SchSNo,ClalistID

    5.删除重复记录,多字段


    delete from clalist where exists
    (select 1 from clalist b
    where clalist.ClalistID=b.ClalistID and clalist.SchSNo=b.SchSNo
    group by ClalistID,SchSNo having count(*) > 1)
    and ClaListSNo not in (select min(ClaListSNo) from clalist group by ClalistID,SchSNo having count(*) > 1)

  • 相关阅读:
    zzuli2470: 迷宫
    zzuli2460: 楼上真的是签到题
    zzuli2460: 楼上真的是签到题
    洛谷P1044 :栈(卡特兰数)
    洛谷P1044 :栈(卡特兰数)
    洛谷P1056:排座椅(贪心)
    代码块地址
    tabBarItem动画
    vim Podfile
    webView进度条
  • 原文地址:https://www.cnblogs.com/wangdodo/p/6407002.html
Copyright © 2011-2022 走看看