作用:是对整体数据的一个筛选操作
语法:
1.判断的符号
=(!=<>不等于)>>=<<=2.拼接不同的条件的关键字
andornot3.查询对应的区间值
between 小值 and 大值[小值,大值] 查询两者之间的范围值
4.查询具体在哪个范围中
in(1,21,333,444) 指定范围
5.模糊查询 like% 通配符 _ 通配符
like"%b" 匹配以b结尾的任意长度的字符串
like"b%" 匹配以b开头的任意长度的字符串
like"%b%" 匹配字符串中含有b的任意长度的内容
like"__b" 匹配总长度为3个字符,任意内容的字符串,并且以b结尾
like"b_" 匹配总长度为2个字符,任意内容的字符串,并且以b开头
# 1.查询id大于等于3小于等于6的数据select id,name,age from emp where id>=3and id<=6;select id,name from emp where id between3and6; 两者等价
# 2.查询薪资是20000或者18000或者17000的数据select*from emp where salary=20000or salary=18000or salary=17000;select*from emp where salary in(20000,18000,17000);# 3.查询员工姓名中包含字母o的员工的姓名和薪资
模糊查询 like% 匹配任意多个字符
_ 匹配任意单个字符
select name,salary from emp where name like'%o%';# 4.查询员工姓名是由四个字符组成的 姓名和薪资 char_length()select name,salary from emp where char_length(name)=4;# 5.查询id小于3或者id大于6的数据select*from emp where id notbetween3and6;# 6.查询薪资不在20000,18000,17000范围的数据select*from emp where salary notin(20000,18000,17000);# 7.查询岗位描述为空的员工姓名和岗位名 针对null不用等号 用isselect name,post from emp where post_comment =NULL; 不行
select name,post from emp where post_comment isNULL;
表数据#创建表create table emp( id int not null unique auto_increment, name varchar(20) not null, sex enum('male','female') not null default 'male', #大部分是男的 age int(3) unsigned not null default 28, hire_date date not null, post varchar(50), post_c