增加
1、在表中插入数据
命令:insert into 表名 (列名 ,列名) values (值,值)
例如:insert into student (name,sex,age,grade) values (‘张三’,1,13,26)
删除
1、删除表格
命令:drop table 表名
例如:drop table student
修改
1、修改表中的数据
命令:update from 表名 set 列名=新值
例如:update from student set grade=36
查找
1、基础查找表的数据
命令:select 要查询的数据列名(*) from 表名 where 筛选条件(无法对分组后的数据进行筛选)
例如:select name fron student where grade<30 //查找分数小于30分的学生名字
例如:select * fron student where grade<30 //查找分数小于30分的所有学生信息
2、高级查找表的数据
命令:select 要查询的数据列名(*) from 表名 where 筛选条件 group by 列名(分组)having 筛选条件(只能对分组后的数据进行筛选)order by 排序方式(控制数据最后输出的排列方式有正序:asc、倒叙:desc)】
例如:通过性别分组,sex=1的正序排序后,查找分数小于30分的学生名字
select name fron student where grade<30 [group by sex having sex=1 order by asc]
**多条件查询**
命令:其他相同,where后面的条件用and链接
例如:....... where age=13 and grade=100
3、多个表同时查找(内连接查询)
命令:select 要查询的数据列名(*) from 表名1,表名2 where 筛选条件(例如表名1.列明=表明2.列明)
例如:查找学生表和家长表,找到 学生表里名字跟家长表里的孩子列 对应的数据
select * from student,parent where student.name=parent.child
**使用别名**
命令:select 要查询的数据列名(*) from 表名1 表1别名,表名2 表2别名 where 筛选条件(例如表名1别名.列明=表明2别名.列明)
例如:查找学生表和家长表,找到 学生表里名字跟家长表里的孩子列 对应的数据
select s.name,p.name from student s,parent p where s.name=p.child
4、其他关键字查询(子查询)
**带In关键字的子查询1**
命令:第一个select语句 did in (第二个select语句)
例如:查询父母表里年龄为50岁的人孩子的数据,然后给外层的查询语句使用。
select * from student where did in select child from parent where age=50
**带In关键字的子查询2**
命令:第一个select语句 did not in (第二个select语句)
例如:查询父母表里年龄**不**为50岁的人孩子的数据,然后给外层的查询语句使用。
select * from student where did not in select * from parent where age=50