本帖最后由 bambino2006 于 2011-11-15 10:09:23 编辑

解决方案 »

  1.   

    delete from aaa where dept not in (select dept from aaa where name = 'A')
      

  2.   

    create table aaa(ID int,NAME varchar2(10),DEPT varchar2(10))insert into aaa values(1 ,'A', '01')  insert into aaa values(2 ,'B', '01')insert into aaa values(3 ,'C', '03')
    delete from aaa where dept not in (select dept from aaa where name = 'A')select * from aaa/*
            ID NAME       DEPT      
    ---------- ---------- ----------
             1 A          01        
             2 B          01        2 rows selected.
    */
      

  3.   


    delete from AAA
    where DEPT <> '01'; --这个01 你可以通过查询得出,但是根据你的描述写死也是可以的。--不写死
    delete from AAA
    where DEPT <>(select DEPT from dept where NAME = 'A');
      

  4.   

    楼上没有看清楚,删除AAA的同时,要把BBB表中的数据也删除!delete from bbb where bbb.dept not in (select bbb.dept from aaa,bbb where aaa.dept=bbb.dept and aaa.name = 'A');delete from aaa where dept not in (select dept from aaa where name = 'A');