使用Where子句
如何使用条件限制返回的结果集
过滤数据:关键字:WHERE
SELECT 字段列表 FROM 表名 WHERE 过滤条件;
过滤条件一般由要过滤的字段、操作符、限定值三部分组成;
例如:
SELECT stu_id,stu_name FROM student
WHERE gender = '男';
常用操作符
介绍常见的操作符
过滤单个值
如何使用单个值过滤数据
SELECT * from student where age>15;
过滤NULL值
如何过滤为NULL值的数据
SELECT * from student where teacher_id is NULL;
过滤集合
如何从结果集中过滤特定的集合
SELECT * from student where age BETWEEN 10 and 15 ORDER BY age;
SELECT * from student where birth_day BETWEEN '2005-01-01' and '2008-12-31';
SELECT * from student where age IN (10,11,15) ;
SELECT * from student where stu_name IN ('牛思静','刘佳乐','李佳欣') ;
SELECT * from student where stu_id NOT IN ('S20160001','S20160002') ;
BETWEEN 与 IN 的区别:
【BETWEEN。。。AND。。。】:返回的结果数值是连续的