表1:                                      表2:
编码       属性                            编码    
A          0                                 A
A          1                                 B 
B          1                                 C
B          0                                 D
C          0                                 F
D          1 
我想删除表2中的内容,但是需要判断。如果表2中的编码在表一中属性只有0,就删除;只要有1(不管有没有0)就不删;
编码在表1中无记录也要删除。我不知道怎么写判断语句,还请高手指点~~
       

解决方案 »

  1.   


    --试试:
    delete from 表2 a where not exists( select 1 from 表1 b where a.编码=b.编码 and exists(select 1 from tab1 c where c.编码=b.编码 and c.属性=1));
      

  2.   

    delete from 表2 where not exists (select 1 from 表1 where 编码=表2.编码 and 属性=1)
      

  3.   


    delete from 表2 a 
    where not exists(select 1 from 表1 b where a.编码=b.编码 and b.属性=1)
    delete from 表2 a 
    where a.编码 in (select b.编码 from 表1 b where a.编码=b.编码 and b.属性=0)