or和and的使用
查找学生姓名以’李’开头或者年龄为’20’的学生信息
select *from student where name like '李%' or age = '20'
查找学生姓名以’李’开头并且年龄为’20’的学生信息
select *from student where name like '李%' and age = '20'
查找学生姓名以’李’开头或者年龄为’20’性别为’女’的学生信息
select *from student where name like '李%' or age = '20' and sex = '女'
查找学生姓名以’李’开头性别为’女’或者年龄为’20’性别为’女’的学生信息
select *from student where (name like '李%' or age = '20') and sex = '女'
between的使用
查找学生年龄在20到21之间(包含20和21)的学生信息
select *from student where age between 20 and 21
查找学生年龄不在20到21之间(包含20和21)的学生信息
select *from student where age not between 20 and 21
in的使用
查找学生年龄在20到21之间(包含20和21)的学生信息
select *from student where age in('20','21')
相当于
select *from student where age = '20' or age = '21'
查找学生年龄不在20到21之间(包含20和21)的学生信息
select *from student where age not in('20','21')
is null 和增加列
上面我们没有地址这一列数据,现在我们插入地址列,增加信息
更新数据添加一列
alter table student
add address varchar(10)
查询更新后的信息
select *from student
更新增加列的内容
update student
set address = '北京'
where id = '3'
update student
set address = '上海'
where id = '4'
update student
set address = '广州'
where id = '5'
update student
set address = '深圳'
where id = '6'
update student
set address = '北京'
where id = '7'
我们增加一部分内容即可,不要全部增加
查询地址是否为空
select *from student where address is null
查询地址是否不为空
select *from student where address is not null