数据表:
下面来测试几个 特殊比较运算符
(1)between value1 ang value2 大于等于value1,且小于等于value2。也就是取闭区间 【value1,value2】
select * from employees where id between "B1001" and "B1003";
(2)
is null ---》指定值等于null
我这个表还没有空值,先加个字段age进去
显示表结构:
desc employees;
修改表 增加一个字段 age
alter table employees
add(
age int);
更新表数据
update employees
set age=20 where sex="男";
查询年龄为null的员工信息
select * from employees where age is null;
更新表中age为空的age值
update employees
set age=18 where age is null;
查询女生的姓名
select name from employees
where sex="女";
(2)in(list) --->等于括号里多个值的任意之一
查询男员工中名字叫小蓝的工号:
方法一:
select id from employees where name="小蓝" and sex="男";
方法二:子查询(当然完全没必要这样做)用in()
select id from employees
where name="小蓝" and id in(
select id from employees
where sex="男");
(4)like 字符串匹配
查询名字以 蓝 开头的职工信息
select *from employees where name like "蓝%";
查询名字里面有 蓝 字的职工信息
select *from employees where name like "%蓝%";