zoukankan      html  css  js  c++  java
  • 删除重复记录(Mysql,SqlServer,Sqlite)

    Mysql中有重复的数据:

    select resource_id,count(1) from t_resource_apptype_releation  GROUP BY resource_id having count(1)>1 order by count(1) desc

    删除一下吧:

    delete a from t_resource_apptype_releation as a,
    (
    select *,min(id) from t_resource_apptype_releation group by resource_id having count(1) > 1
    ) as b
     where a.resource_id = b.resource_id and a.id > b.id;

    创建一个唯一索引,防止再发生类似事件。

     

    现在开始玩SQL SERVER 

    查看:

    select resource_id,count(1) from t_resource_apptype_releation  GROUP BY resource_id having count(1)>1 order by count(1) desc 

    删除:

    delete aa from t_resource_apptype_releation aa where  exists(select * from t_resource_apptype_releation where aa.id>id and  resource_id=aa.resource_id)

    Sqlite这样:

    delete from T_RESOURCE_APPTYPE_RELEATION where id not in (select min(id) from T_RESOURCE_APPTYPE_RELEATION  group  by resource_id);
  • 相关阅读:
    centos 6 升级gcc
    linux fdisk 分区
    centos使用163的源
    工作流发布成功但不能自动启动
    可怕的断电
    FTP 之 550 permission denied
    Track & Trace
    AutoKey思想的應用(二)
    Windows登錄過程淺析
    snapshot.exe出現異常
  • 原文地址:https://www.cnblogs.com/littlehb/p/3247276.html
Copyright © 2011-2022 走看看