增加
insert into 表名(增加的抽象属性1,增加的抽象属性2)values(具体的属性1),(具体的属性2);
查询:
select 查询的属性 from 表名;
select stu_no,stu_name from student;
别名:
结果集表头列的别名
(原名称后用as+别名/空格+别名)
select stu_no,stu_name as sn from student;
select stu_no,stu_name sn from student;
举例:创建exam_table表
插入测试数据:
distinct -----去重
select distinct 列名 from 表名
order by:
排序
升序:asc 降序:desc
select * from 表名 order by desc/asc;
按语文课成绩降序排列学生
升序排列学生数学课成绩
条件查询:
select * from 表名 where 条件;
查询总分大于250 分的姓名和学号
范围查询:(between...and )
学号为1到3之间的学生信息
范围查询(in)查询学号为1和3的学生信息:
is null 、is not null
select * from 表名 where 列名 is null/not null
查询表exam_result中id为空的学生信息
查询表exam_result中id不为空的学生信息
模糊查询:
select * from 表名 where 列名 like '某%';
查询姓宋的同学信息:
查询姓孙的同学信息:
相对应的,如果你需要查属性后面是确定字数的信息,可以采用
select * from 表名 where 列名 like '某_';
多条件查询:
where 条件一and 条件二
java:if(条件一 &&条件二)
where 条件一 or 条件二
java:if(条件一||条件二)
where 条件一 and (条件二 or 条件三)
java:if(条件一&&(条件二 ||条件三)
查询数学成绩大于90并且语文成绩小于80或者英语成绩大于80的同学信息,并将此信息按照数学成绩降序排列
分页查询(LIMIT操作):
limit:限制的数量条数
offset:偏移量
- 查询前n条信息
select * from 表名 limit n;
- 从第m 条信息开始查询n条信息
方法一:select * from 表名 limit m,n;
- 从第二条信息开始,查询三条信息
方法二:select * from 表名 limit n offset m;
查询满足(xx德或孙xx)并且(数学成绩大于75分或者英语成绩小于70分)
修改:(update)
update 表名 修改的内容 where 修改范围;
修改唐三藏的id为null
默认修改列的所有值:
修改所有人的id为null
- 修改多个列
update 表名 set 修改内容1,修改内容2 where 修改范围;
修改猪悟能的id为3语文成绩为99
修改数学成绩大于75分的前三个信息
删除库和表用drop
删除具体的信息用delete
删除id 等于2的行
注意:where 条件不可以使用别名