where子句之逻辑运算符
作用:检索数据中符合条件
的值
搜索的条件由一个或者多个表达式组成! 结果为 布尔值
运算符 | 语法 | 描述 |
---|---|---|
and && | a and b a && b | 逻辑与,两个都为真,结果为真 |
or || | a or b a|| b | 逻辑或,其中一个为真,结果为真 |
not ! | not a !a | 逻辑非,真为假,假为真 |
尽量使用英文
模糊查询
运算符 | 语法 | 描述 |
---|---|---|
IS NULL | a is null | 如果操作符为null,结果为真 |
IS NOT NULL | a is not null | 如果操作符不为null,结果为真 |
between … and | a between b and c | 若a在b和c之间,结果为真 |
like | a like b | sql匹配,如果a匹配b,结果为真 |
in | a in( a1,a2,a3…) | 假設a在a1,a2…其中的某一个值,结果为真 |
-- 查询姓刘的同学
-- like结合 %(0到任意哥字符) _ (一个字符)
select studentName from `student` where studentName = '刘%'
-- 查询1001 1002 1003号学员
select studentName from `student` where studentNo IN (1001,1002,1003)