日期:2014-05-19  浏览次数:20579 次

字段中有数组怎么查询?
有很多记录每个记录里有个字段(存放的是数组的值[如:1,2,3,4,5,6])   目前要查出数组值里必须都大于3的所有记录(比如:5,5,5,5,5,5   或   5,6,4,6,5,6)
请问怎么写WHERE???

------解决方案--------------------
declare @a table(a varchar(100))
insert @a select '1,2,3,4,5,6 '
union all select '5,5,5,5,5,5 '
union all select '5,6,4,6,5,6 '

select * from @a where patindex( '%[0-3]% ',a)=0

------解决方案--------------------
select * from @a where patindex( '%,[0-3],% ', ', '+a+ ', ')=0
union
select * from @a where patindex( '[0-3],% ',a+ ', ')=0
union
select * from @a where patindex( '%,[0-3] ', ', '+a)=0

试试