比如一个表 有ID 、TITLE、 CONTENT 等字段。现在要删除 同一ID记录条数只有一条的记录。这个语句怎么写 求救。

解决方案 »

  1.   

    delete from tt t
      where exists(
    select 1 from (select id,count(1)c from tt group by id)
     where c=1 and id=t.id)
      

  2.   

    delete * from tablename t 
    where not exists (select 1 from tablename t2 where t2.id = t.id group by t2.id having count(id) > 1);
      

  3.   

    delete from tt where (id,title,content)
    in(select id,title,content
    from 
    (select tt.*,row_number() over(parition by id,title,content order by id) rn
    from tt )
    where rn>1)
      

  4.   

    delete from tt where id in (select id from tt group by having count(1)=1)
      

  5.   


    掉了id
    delete from tt where id in (select id from tt group by id having count(1)=1)