select * from (
select id,dw,xm,'0' sign from tbname where ny='199607'
minus
select id,dw,xm,'0' sign from tbname where ny='199608')
union all(
select id,dw,xm,'1' sign  from tbname where ny='199608'
minus
select id,dw,xm,'1' sign  from tbname where ny='199607');

解决方案 »

  1.   

    insert into new_table(id,dw,xm,sign) select id,dw,xm,'1' from old_table where ny='199608' and xm not in  select ny from old_table where ny='199607';
    insert into new_table(id,dw,xm,sign) select id,dw,xm,'0' from old_table where ny='199607' and xm not in  select ny from old_table where ny='199608';
      

  2.   

    insert into new_table(id,dw,xm,sign) select id,dw,xm,'1' from old_table
     where ny > '199606'
     and   ny < '199609'
     and xm not in (select xm from old_table where  ny < '199607')insert into new_table(id,dw,xm,sign) select id,dw,xm,'0' from old_table
     where ny < '199607'
     and xm not in (select xm from old_table where  ny > '199606' and ny < '199609')
      

  3.   

    create table t_new as
    select  *  from  (  
    select  id,dw,xm,'0'  sign  from  tbname  where  ny='199607'  
    minus  
    select  id,dw,xm,'0'  sign  from  tbname  where  ny='199608')  
    union  all(  
    select  id,dw,xm,'1'  sign    from  tbname  where  ny='199608'  
    minus  
    select  id,dw,xm,'1'  sign    from  tbname  where  ny='199607');
      

  4.   

    select id,dw,xm,0 
    from old_table 
    where ny=199607 
    and xm not in  (select xm from old_table where ny=199608)
    union all
    select id,dw,xm,1 
    from old_table 
    where ny=199608 
    and xm not in  (select xm from old_table where ny=199607)这样应该没问题吧~~~~
      

  5.   

    insert into new_table(id,dw,xm,sign) select id,dw,xm,'1' from table 
     where ny > '199606'
     and   ny < '199609'
     and xm not in (select xm from table where  ny < '199607')