- SQL code
create table temp_T1( ID int, U1 varchar(100), U2 varchar(100) )insert into temp_T1 select 1,'AA2,BB3,AA,AA4',''insert into temp_T1 select 2,'DD1,DD2',''insert into temp_T1 select 3,'CC1',''insert into temp_T1 select 4,'EE8,AA',''insert into temp_T1 select 5,'XX',''insert into temp_T1 select 6,'','TT'insert into temp_T1 select 7,'CCCC',''insert into temp_T1 select 8,'','AA'insert into temp_T1 select 9,'BXXX',''select * from temp_T1ID U1 U2----------- ---------------------------------------------------------------- ----------------------------------------------------------------1 AA2,BB3,AA,AA4 2 DD1,DD2 3 CC1 4 EE8,AA 5 XX 6 TT7 CCCC 8 AA9 BXXX (9 行受影响)
---------------------------------------------
找出U1栏中有AA的或者U2栏中没有AA的行。请问如何写这个SQL语句比较好呢?
------解决方案--------------------
','+U1+',' LIKE '%,AA,%'
------解决方案--------------------
- SQL code
--漏写分隔符select *from tbwhere ','+u1+',' like '%,AA,%' or ','+u2+',' not like '%,AA,%'