一个SQL查询语句如何写?

来源:百度知道 编辑:UC知道 时间:2024/09/21 21:02:41
A 表 ID NAME NO
1 2 1,2,3
2 2 1,2,4
3 3 1,5
4 2 1,3
请问 要查询所有NAME=2 并且 NO 数组内有 3 的记录
ID NAME NO
1 2 1,2,3
2 2 1,2,4
3 3 1,5
4 2 1,3
请问 要查询所有NAME=2 并且 NO数组内有 3 的记录

select * from a where name=2 and no like '%3%'

select *
from A
where name=2 and no=3;

select * from A where name=2 and no=3

select * from A where name='2' and no like'%3%'

select *
from a
where name=2 and no like '%3'

这要看NO里边是否包含大于9的数字了,如果没有的话直接这么写
select * from a where name=2 and no like '%3%'
否则,这么写
select * from a where name=2 and (no like '3,%' or no like '%,3,%' or no like '%,3')