只用IN操作符不对头,IN的逻辑就是“或”,number IN ('1','4','6','13')就相当于number='1' or number='4' or number='6' or number='13',而你的number中没有13(10个值里面没13),则或上等于13的,过滤效果就等同于没加这个条件,于是查出3条记录。
按你的意图,似乎是应该查出0条记录,大概需要写成如下命令:
select number from ABC
where number IN ('1','4','6','13')
and exists( select 1 from ABC where number='1' )
and exists( select 1 from ABC where number='4' )
and exists( select 1 from ABC where number='6' )
and exists( select 1 from ABC where number='13' )
绝对匹配就是查询字段跟条件相等
比如:学生表里面,你要查询姓名叫‘张三’的人
select * from Student where name='张三'
可以使用like 或者=
LIKE 操作符用于在 WHERE 子句中搜索列中的指定模式。
=判断值是否为某个特殊的固定值
例子:
Persons 表:
Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing
查询city 为Beijing的记录
select * from persons where City = 'Beijing'
结果
Id LastName FirstName Address City
3 Carter Thomas Changan Street Beijing
从 "Persons" 表中选取居住在以 "g" 结尾的城市里的人:
SELECT * FROM Persons WHERE City LIKE '%g'
结果集:
Id LastName FirstName Address City
3 Carter Thomas Changan Street Beijing