Mysql 中的升序、降序以及随机查询

1. 升序

select time,A from table1 order by time asc limit 10;

+---------------------+---------+
| time                | A       |
+---------------------+---------+
| 2022-12-14 20:40:32 | 294.368 |
| 2022-12-14 20:41:02 | 293.819 |
| 2022-12-14 20:41:32 | 293.956 |
| 2022-12-14 20:42:03 | 293.681 |
| 2022-12-14 20:43:01 | 292.857 |
| 2022-12-14 20:43:31 | 292.308 |
| 2022-12-14 20:44:02 | 291.896 |
| 2022-12-14 20:44:32 | 291.346 |
| 2022-12-14 20:45:02 | 291.209 |
| 2022-12-14 20:45:32 | 291.896 |
+---------------------+---------+
10 rows in set (0.00 sec)
2. 降序

select time,A from table1 order by time desc limit 10;

+---------------------+---------+
| time                | A       |
+---------------------+---------+
| 2022-12-15 09:40:32 | 270.604 |
| 2022-12-15 04:09:32 | 274.451 |
| 2022-12-16 10:48:31 | 179.121 |
| 2022-12-16 12:34:31 | 180.769 |
| 2022-12-14 21:29:32 | 270.467 |
| 2022-12-16 05:45:33 | 179.945 |
| 2022-12-15 08:00:31 | 226.374 |
| 2022-12-15 14:32:52 | 280.632 |
| 2022-12-16 09:35:02 | 179.945 |
| 2022-12-16 09:53:31 | 178.159 |
+---------------------+---------+
10 rows in set (0.01 sec)

 3.随机

select time,A from table1 order by rand() limit 10;

 +---------------------+---------+
| time                | A       |
+---------------------+---------+
| 2022-12-15 09:40:32 | 270.604 |
| 2022-12-15 04:09:32 | 274.451 |
| 2022-12-16 10:48:31 | 179.121 |
| 2022-12-16 12:34:31 | 180.769 |
| 2022-12-14 21:29:32 | 270.467 |
| 2022-12-16 05:45:33 | 179.945 |
| 2022-12-15 08:00:31 | 226.374 |
| 2022-12-15 14:32:52 | 280.632 |
| 2022-12-16 09:35:02 | 179.945 |
| 2022-12-16 09:53:31 | 178.159 |
+---------------------+---------+
10 rows in set (0.01 sec)

posted @ 2022-12-18 16:01  华小电  阅读(279)  评论(0编辑  收藏  举报