MySQL语法分类 DQL(3)排序查询
为了更好的学习这里给出基本表数据用于查询操作
create table student (
id int,
name varchar(20),
age int,
sex varchar(5),
address varchar(100),
math int,
english int
);
insert into student
(id,name,age,sex,address,math,english)
values
(1,'马云',55,'男','杭州',66,78),
(2,'马化腾',45,'女','深圳',98,87),
(3,'马景涛',55,'男','香港',56,77),
(4,'柳岩',20,'女','湖南',76,65),
(5,'柳青',20,'男','湖南',86,NULL),
(6,'刘德华',57,'男','香港',99,99),
(7,'玛德',22,'女','香港',99,99),
(8,'德玛西亚',18,'男','南京',56,65)
;
语法
order by 排序字段1,排序字段2,...排序字段n;
根据数学成绩排序(默认升序)
升序
select * from student order by math;
select * from student order by math asc;
降序
select * from student order by math desc;
按照数学成绩升序,如果成绩一样,按照英语成绩升序
select * from student order by math asc, english asc;
点击返回 MySQL 快速学习目录