删除重复数据

select   *    from  
(
    
-- 获取冗余数据中的唯一最小行数据
     select   *    from  table_1 t1
     
where  t1.id  in  
    (
        
select   min (t2.id)  from  table_1 t2 
        
group   by  t2.employeeid  having  t1.employeeid = t2.employeeid  and   count ( * >   1
    )
    
union   all
    
-- 获取非冗余数据
     select   *   from  table_1 t4  where  t4.id  in
    (
        
select   min (t3.id)  from  table_1 t3
        
group   by  t3.employeeid  having  t4.employeeid  =  t3.employeeid  and   count ( * =   1
    )
) t5 
order   by  id

你可能感兴趣的:(删除)