模糊查询(比较运算符)
%(0到任意个字符) _(一个字符)
- Like
-- 查询姓刘的同学
-- like结合%(0到任意个字符) _(一个字符)
SELECT `studentno`,`studentname` FROM `student`
WHERE `studentname` LIKE "刘%"
-- 查询姓刘的同学 2个字
SELECT `studentno`,`studentname` FROM `student`
WHERE `studentname` LIKE "刘_"
-- 查询姓刘的同学 3个字
SELECT `studentno`,`studentname` FROM `student`
WHERE `studentname` LIKE "刘__"
-- 查询名字中间带有馨字的同学
SELECT `studentno`,`studentname` FROM `student`
WHERE `studentname` LIKE "%馨%"
2. in里面表示具体的一个值或者多个值,不支持类似于 IN ("北京%")
这样的语句
-- 查询1001,1002,1003号学生
SELECT `studentno`,`studentname` FROM `student`
WHERE `studentno` IN(1001,1002,1003)
-- 查询在北京朝阳,广东深圳的同学
SELECT `studentno`,`studentname`,`address` FROM `student`
WHERE `address` IN ("北京朝阳","广东深圳")
3. null 或者 not null
我们先看一下现在表的数据
-- 查询地址为空的同学 null , ""
SELECT `studentno`,`studentname`,`address` FROM `student`
WHERE `address` IS NULL OR `address`=""
-- 查询出生日期为空的同学 null
SELECT `studentno`,`studentname`,`borndate` FROM `student`
WHERE `borndate` IS NULL
-- 查询出生日期不为空的同学 null
SELECT `studentno`,`studentname`,`borndate` FROM `student`
WHERE `borndate` IS NOT NULL