日期:2014-05-18 浏览次数:20603 次
create table plat_uidlist(Uid varchar(10) , Areaid int , State int) insert into plat_uidlist values('2335435' ,8 ,0 ) insert into plat_uidlist values('2335436' ,8 ,1 ) insert into plat_uidlist values('2335437' ,2 ,2 ) insert into plat_uidlist values('2335438' ,8 ,3 ) insert into plat_uidlist values('2335439' ,3 ,0 ) insert into plat_uidlist values('2335440' ,8 ,0 ) insert into plat_uidlist values('6677889' ,8 ,0 ) insert into plat_uidlist values('1234578' ,4 ,0 ) insert into plat_uidlist values('4980010' ,8 ,0 ) insert into plat_uidlist values('4980099' ,8 ,0 ) go --符合条件的 select * from plat_uidlist where charindex('888' , Uid) > 0 or charindex('666' , Uid) > 0 or charindex('999' , Uid) > 0 or charindex('AAAA' , Uid) > 0 or right(Uid,4) = 'ABCD' or right(Uid,4) = 'AABB' or right(Uid,4) = 'ABAB' or right(Uid,4) = 'AAAB' or right(Uid,4) = 'ABBB' or Uid between '4980000' and '4989999' or (areaid = 8 and state <> 3) /* Uid Areaid State ---------- ----------- ----------- 2335435 8 0 2335436 8 1 2335440 8 0 6677889 8 0 4980010 8 0 4980099 8 0 (所影响的行数为 6 行) */ --不符合条件的 select * from plat_uidlist where Uid not in ( select Uid from plat_uidlist where charindex('888' , Uid) > 0 or charindex('666' , Uid) > 0 or charindex('999' , Uid) > 0 or charindex('AAAA' , Uid) > 0 or right(Uid,4) = 'ABCD' or right(Uid,4) = 'AABB' or right(Uid,4) = 'ABAB' or right(Uid,4) = 'AAAB' or right(Uid,4) = 'ABBB' or Uid between '4980000' and '4989999' or (areaid = 8 and state <> 3) ) /* Uid Areaid State ---------- ----------- ----------- 2335437 2 2 2335438 8 3 2335439 3 0 1234578 4 0 (所影响的行数为 4 行) */ --drop table plat_uidlist
------解决方案--------------------
create table plat_uidlist(Uid varchar(10) , Areaid int , State int)
insert into plat_uidlist values('2335435' ,8 ,0 )
insert into plat_uidlist values('2335436' ,8 ,1 )
insert into plat_uidlist values('2335437' ,2 ,2 )
insert into plat_uidlist values('2335438' ,8 ,3 )
insert into plat_uidlist values('2335439' ,3 ,0 )
insert into plat_uidlist values('2335440' ,8 ,0 )
insert into plat_uidlist values('6677889' ,8 ,0 )
insert into plat_uidlist values('1234578' ,4 ,0 )
insert into plat_uidlist values('4980010' ,8 ,0 )
insert into plat_uidlist values('4980099' ,8 ,0 )
select * from plat_uidlist
where
charindex('888',uid)>0 or ch