select 序号, 更新年月 , 取消年月 , 公司 from table where 取消年月='00000000' or (取消年月<>'00000000' and 更新年月 not in (select 更新年月 from table where 取消年月='00000000') )
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' )
select 序号, 更新年月 , 取消年月 , 公司 from table where 取消年月='00000000' or (取消年月<>'00000000' and 更新年月+ convert(char(2),序号) not in (select 更新年月+ convert(char(2),序号) from table where 取消年月='00000000') ) 唉,我又捣了一次浆糊
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
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
取消年月='00000000' or (取消年月<>'00000000'
and 更新年月 not in (select 更新年月 from table where 取消年月='00000000') )
取消年月='00000000' or (取消年月<>'00000000'
and 更新年月+ convert(char(2),序号) not in (select 更新年月+ convert(char(2),序号) from table where 取消年月='00000000') ) 唉,我又捣了一次浆糊
or
select * from tb A where 取消年月='00000000' and (select count(*) from tb B where A.序号=B.序号 and A.更新年月=B.更新年月)=1
c_date<>'00000000') b where a.c_id <> b.c_id or a.c_datetime <> b.c_datetime