这里我们可以先了解一下全列查询方法:
select from 要查询的表明;
首先,我们需要实现一个表,如图:

示例
插入两条记录 插入元素数量必须和定义表的列的数量及顺序一致
insert into student values (100,10000,‘唐先生’ ,NULL);
insert into student values (101,10001,‘孙先生’,‘11111’);


示例:
INSERT INTO student (id, sn, name)VALUES
(102, 20001, ‘曹孟德’),
(103, 20002, ‘孙仲谋’);


首先创建一个查询的测试用表

通常情况下,不建议使用 * 进行全列查询.
- 查询的列越多,同样就意味着需要传输的数据量越大.
- 可能会影响到索引的使用.
select * from 表名称;

指定列查询,顾名思义就是不受定义的表的顺序约束限制来查询
select id,name,english (这里可以更变为任意表定义的列) from 表名;

- 表达式中不包含字段
select id,name,10,from 表名;

- 表达式包含一个字段
select id,name,english+10 from 表名;

- 表达式包含多个字段
select id,name,chinese+math+english from 表名;

查询时,在字段表达式后方加上新的名称更正为别名
select id,name,chinese+math+english 总分 from 表名;

这里我们可以先插入一组元素

如图,查找出重复的数据:

使用 distinct 关键字进行去重操作;
select distinct math from 表名;

排序操作分为两类
- ASC 为升序 (从小到大).
- DESC 为降序 (从大到小).
默认为 ASC
select 列名,列名... from 表名 order by 列名 DESC/ASC;

依然以这个表格为例.
(1)最基本的排序展示
以语文成绩为例:
ASC 升序排列:

DESC 降序排列:

(2)使用表达式以及别名排序
表达式排序:

别名排序:

(3)对多个字段进行排序
select name,math,chinese,english from exam_result order by math DESC ,chinese,english;

注: 对字段排序时,会对第一列优先排序,如果第一列无序,优先排第一列,轮不到第二列的排序.
比较运算符:

逻辑运算符:

(1) 基本查询
查询英语不及格的人
select name,english from exam_result where english < 60;

查询语文成绩优于英语成绩的
select name,chinese,english from exam_result where chinese > english;

查询总分在200分以下的同学
select name,chinese+math+english from exam_result where chinese + math + english<200;

注: where 可以使用表达式,但是不可以使用别名.
(2)AND 和 OR
查询语文成绩大于80分且英语成绩大于80分的同学.
select name,chinese,english from exam_result where chinese>80 and english>80;

查询语文成绩大于80分或者英语成绩大于80分的同学
select name,chinese,english from exam_result where chinese >80 or english >80;

注. AND的优先级高于OR,在同时使用时,需要使用小括号()包裹优先执行的部分
(3)范围查询
查询语文成绩在 [80,90] 之间的同学
select name,chinese from chinese where between 80 and 90;

同样这里也可以用 and 方法来实现
select name,chinese from exam_result where chinese >=80 and chinese <= 90;

查询数学成绩是 58 或者 59 或者 98 或者 99 分的同学及数学成绩
select name,math from exam_result where math in(58,59,98,99);

同样的这里也可以用 or 方法来实现.
select name,math from exam_result where math = 58 or math = 59 or math = 98 or math = 99;

%匹配任意多个字符
select name from exam_result where name like '%孙';

_ 严格匹配一个任意字符
select name from exam_result where name like '......';

查询同学语文成绩是否为NULL;
select name,chinese from exam_result where chinese is not NULL;
select name,chinese from exam_result where chinese is NULL;

以 id 进行分列
select id,name,math,english,chinese from exam_result order by id limit 3 offset 0;
select id,name,math,english,chinese from exam_result order by id limit 3 offset 3;
select id,name,math,english,chinese from exam_result order by id limit 3 offset 6;
分页方法的意思是 limit (几个元素) offset (从第几个 id 算起).


当前表格如图:

delete from exam_result where name = '唐三藏';

首先准备一张要删除的表,如图.

删除整张表:
delete from test(表名);

总结: 到此为止,已经介绍了数据库的最基本的增删查改的操作,如有不足之处,欢迎指出!