1.基础查询
select * from student;
select是关键字,表示查询,*就是显示所有字段,from表示从哪个表中查询
2.条件查询
查询班级号为20201001的学生
select * from student where class_num='20201001';
WHERE关键字就是表示条件class_num='20201001'。class_num就是列名,该列中是20201001的字段来表示出来。
查询班级号为20201001的学生的姓名和性别
select name,sex from student where class_num='20201001';
条件查询的and、or、not
这里and就表示并且
查询班级号为20201001并且性别为男的学生姓名
select name from student where class_num='20201001' and sex='男';
查询班级号为20201001或者性别为男的学生姓名
select name,sex from student where class_num='20201001' or sex='男';
查询不在班级号为20201001班的所有学生信息
select * from student where not class_num='20201001';
3.排序
这里就要用到order by关键字了,格式是
orber by '字段名' ---->表示按照哪个字段来排序
eg:查询班级号为20201001的学生的所有信息按照age排序
select * from stduent where class_num='20201001' order by age;
如果要反过来,按照年龄从高到低来排序,我们可以加上DESC表示“倒序”
select * from stduent where class_num='20201001' order by age DESC;