1 use learn_db; 2
3 # 排序查询
4 /*
5 select + 字段名/*(多个字段名用逗号隔开) from + 表名 order by + 要排序的字段名
6 order by + 字段名 [asc | desc]
7 order by 默认为升序
8 order by + 字段名 desc -->倒序
9 */
10
11 select student_name, exam_python from dis_exam order by exam_python ; 12 select student_name, exam_python from dis_exam order by exam_python desc ; 13
14 select student_name, exam_python+exam_mysql+exam_linux as sum from dis_exam order by sum desc ; 15
16 # 分组查询 select + 字段名/(*) from 表名 group by + 按哪个字段分类 17 select student_name from dis_exam group by student_name ; 18
19 # 分组后条件筛选用having select + 字段名/(*) from 表名 group by + 按哪个字段分类 having [条件]
20 select student_name , sum(exam_mysql) from dis_exam group by student_name having sum(exam_mysql)>100 ; 21
22 # 计数查询 select count(字段名/(*)) from 表名 [条件]
23 select count(*) from dis_exam ; 24
25 # 平均值查询 select avg(字段名) from + 表名 26 select sum(exam_mysql)/count(student_name) from dis_exam ; 27 select avg(exam_mysql) from dis_exam ; 28
29 # 最值 30 # 最大值 select max(字段名/(*)) from + 表名 31 select max(exam_mysql) from dis_exam ; 32 select max(exam_mysql+exam_linux+exam_python) from dis_exam ; 33 #最小值 select min(字段名/(*)) from + 表名 34 select min(exam_mysql) from dis_exam ; 35 select min(exam_mysql+exam_linux+exam_python) from dis_exam ; 36
37 # 查看表中的前x行 select * from + 表名 limit x 38 select * from dis_exam limit 3 ; 39 # 查看跳过x行显示y行 select * from + 表名 limit x,y 40 select * from dis_exam limit 2,1 ;