当前位置: 代码迷 >> Sql Server >> Access 数据库,SQL(多字段联系关系重复数据去除)
  详细解决方案

Access 数据库,SQL(多字段联系关系重复数据去除)

热度:37   发布时间:2016-04-24 10:46:13.0
Access 数据库,SQL(多字段关联重复数据去除)
  --这个表,我这边将这些字段(6个)重复的数据清除,因为之前没做主键、唯一等约束,造成数据重复、混乱! 
  select distinct FPeriod,facctid,fclsid,fobjid,fcyid,fbase from glpnl_20140423bak
  --一共8个字段,我要根据期中六个做联合主键,所以要把这些垃圾数据清除
   **----求大神出现!** 

------解决方案--------------------
1、首先增加一个自增列
2、
delete from employee 
      where emp_no in (select  emp_no from @tb1  group  by  emp_no  having  count(*) > 1) 
       and rowid not in (select min(rowid) from  @tb1  group by emp_no having count(*)>1)
       但是如果没有该rowid字段时,则不能使用这种发放,因为没有办法过滤其中的一行。此时就需要借助于一张临时表,方法是把不重复的记录先放在临时表中,然后删除表中所有的数据,再从临时表中把数据取回即可。
      select distinct * into tmp from employee
      delete from employee
      insert into employee select * from tmp
 
类似这样的,这个是sql server中的,看着改吧

------解决方案--------------------
你给表中增加一个自增列,
delete a from #T a where  exists(select 1 from #T where Name=a.Name and ID<a.ID)

 Name=a.Name这个条件改一下,试试

------解决方案--------------------
老B,沉了沉了沉了
  相关解决方案