排序查询——order by
# 排序查询——order by
order by
排序
asc
代表升序desc
代表降序
# Example
+----+------+------------+---------------+
| id | name | math_score | english_score |
+----+------+------------+---------------+
| 1 | Tom | 20 | 99 |
| 2 | Jim | 59 | 77 |
| 3 | Anna | 77 | 59 |
| 4 | 张三 | 89 | 89 |
| 5 | 李四 | 99 | 20 |
+----+------+------------+---------------+
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 升序
select id,name,english_score from student order by english_score asc;
1
# 降序
select id,name,english_score from student order by english_score desc;
1
+----+------+---------------+
| id | name | english_score |
+----+------+---------------+
| 1 | Tom | 99 |
| 4 | 张三 | 89 |
| 2 | Jim | 77 |
| 3 | Anna | 59 |
| 5 | 李四 | 20 |
+----+------+---------------+
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
编辑 (opens new window)
上次更新: 2022/09/26, 16:55:15