in 用于指定查询与where 一块进行使用,可以用来指定一个或多个,和 “ = ” 差不多
语法:
select * from 表名 where 字段 in (字段对应的值可以是一个或多个)
建个表弄点数据
使用in 与 = 对比
使用 运算符in 进行查询
使用运算符 = 完成上述查询
使用 not 字段 in 和 !=
使用 not 字段 in 和 != 完成查询年龄不是22 的
语法:
select * from 表名 where not 字段 in (字段对应的值可以是一个或多个)
sql 语句
-- in
-- 语法:select * from 表名 where 字段 in(字段对应的值)
-- 查询表中名字是大乔和小乔的数据,并按照id 的降序排列
select * from dbo.test where Name in ('大乔','小乔') order by Id desc
select * from test where Name = '大乔' or Name = '小乔'
-- 使用 not 字段 in 和 != 完成查询年龄不是22 的
-- 查询年龄不是22 的
select * from test where not Age in (22)
-- 查询年龄不是22 的
select * from test where Age != 22