1、使用order by 排序:ASC\DES(升序\降序,默认升序)
题目:查询students表sex="m"的字段显示id,name,age列并按降序排列
mysql> select id,name ,age from students where sex = "m" order by age DESC;
+----+---------+------+
| id | name | age |
+----+---------+------+
| 5 | wendy | 20 |
| 6 | ton | 20 |
| 7 | liy | 18 |
| 2 | hathway | 15 |
+----+---------+------+
4 rows in set (0.00 sec)
2、题目:查询students表sex="m"的字段显示id,name,age列并按升序排列
mysql> select id,name ,age from students where sex = "m" order by age ASC;
+----+---------+------+
| id | name | age |
+----+---------+------+
| 2 | hathway | 15 |
| 7 | liy | 18 |
| 5 | wendy | 20 |
| 6 | ton | 20 |
+----+---------+------+
4 rows in set (0.01 sec)