PID      PNAME     PUNIT      PTYPE
2000     *****     *****      WL
2000     *****     *****      CP
2001     *****     ******     CP
2001     *****     ******     WL
20009    *****     *****      WL
20056    *****      ****      CP
将两个相同的PID删除一个,得到PTYPE为CP的PID先行谢过!

解决方案 »

  1.   

    你这应该只是你表中记录的一小部分吧
    select rowid from tablename where pid in (2000,2001,......)delete from tablename where ptype is not cp and rowid=你所要删除的记录所对应的ROWID
      

  2.   

    这个方法好像行不通,in(2000,2001----------------) ,表里有上千条记录,有重复的也有不重复的,现在就是删除重复的PTYPE为WL的,想想有没有好一点的方法
      

  3.   

    delete from 表名 a where PID in (select PID,count(*) from 表名 group by PID having count(*) > 1)
      

  4.   

    delete from 表名 a where PID in (select PID,count(*) from 表名 group by PID having count(*) > 1) And PTYPE='WL'
      

  5.   

    select distinct * into temptable from tablename
     
    delete from tablenameinsert into tablename select * from temptabledrop table temptable
      

  6.   

    要想提高效率,借助临时表来做:  CREATE TABLE 临时表 AS
      (select PID,count(*) from 表名 group by PID having count(*) > 1)
       上面这句话就是建立了临时表,并将查询到的重复PID的数据插入其中。
       下面就可以进行这样的删除操作了:
      delete from 表名 a where PID in (select PID from 临时表) And  PTYPE='WL'
      完了将临时表删除
      Drop Table 临时表
      

  7.   

    delete from tablename where rowid in (select a.rowid from tablename a,tablename b 
    where a.pid=b.pid and a.ptype <> 'CP')
      

  8.   

    to faysky2():  thanks very much !能否再问一下,现在的PID是float型的,可要的是CHAR(10)型的,在企业管理器里改不了,请问
    有什么改的方法吗?谢谢