Sort statement
- In order to facilitate data view, you can sort the data
- grammar:
select * from 表名
order by 列1 asc|desc,列2 asc|desc,...
- Line data sorted by column 1, if the values of some of the same row 1, column 2 according to the sort, and so on
- The default values in columns in ascending order
- asc ascending order, i.e. ascending
- desc descending order, namely in descending order
Example 1: Query all student information, from small to large sorted by age
select * from students order by age
Example 2: Query all student information, descending order by age, age is the same, then the student number in ascending order
select * from students order by age desc,studentNo
Exercise:
1、查询所有学生信息,按班级从小到大排序,班级相同时,再按学号再按学号从小到大排序