select min(序号) as 序号 、更新年月、min(取消年月) as 取消年月 into #aa from table group by 更新年月
select * from #aa where 取消年月<>'00000000'

解决方案 »

  1.   

    select 序号, 更新年月 ,  取消年月 ,   公司 from table where 
    取消年月='00000000' or (取消年月<>'00000000'
    and 更新年月 not in (select 更新年月 from table where 取消年月='00000000') )  
      

  2.   

    select * from (select * from yourtable where 取消年月='00000000' ) b where not exists (select 1 from yourtable a where a.序号= b.序号and a.更新年月 = b.更新年月 and a.取消年月<>'00000000' )
      

  3.   

    select 序号, 更新年月 ,  取消年月 ,   公司 from table where 
    取消年月='00000000' or (取消年月<>'00000000'
    and 更新年月+ convert(char(2),序号) not in (select 更新年月+ convert(char(2),序号) from table where 取消年月='00000000') )  唉,我又捣了一次浆糊
      

  4.   

    select * from tb A where 取消年月='00000000' and (select count(*) from tb B where A.序号=B.序号 and A.更新年月=B.更新年月 and B.取消年月<>'00000000')=0
    or
    select * from tb A where 取消年月='00000000' and (select count(*) from tb B where A.序号=B.序号 and A.更新年月=B.更新年月)=1
      

  5.   

    zqllyh你的第一段程序是有问题的,没有结果,呵呵,不过改正了就可以了,不能算倒浆糊,只是没测试罢了
      

  6.   

    select a.* from (select * from newtable where c_date ='00000000') a,(select * from newtable where 
    c_date<>'00000000') b where a.c_id <> b.c_id or a.c_datetime <> b.c_datetime