首页 > 数据库 >Mysql 中的升序、降序以及随机查询

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

时间:2022-12-18 16:12:03浏览次数:42  
标签:12 20 14 16 32 降序 2022 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)

标签:12,20,14,16,32,降序,2022,Mysql,升序
From: https://www.cnblogs.com/conpi/p/16990491.html

相关文章

  • docker启动mysql
    将docker启动,执行以下命令:dockerrun-p3306:3306--namemysql\-v/mydata/mysql/log:/var/log/mysql\-v/mydata/mysql/data:/var/lib/mysql\-v/mydata/mysql/c......
  • mysql>date用法
     ......
  • MySQL 卸载与安装(压缩包版)
    1.判断本地是否已经安装MySQL①在运行界面输入services.msc进入服务界面,查看是否有MySQL服务②进入任务管理器,点击服务看是否有MySQL服务2.安装MySQL(压缩包版)1.......
  • windows 本地搭建Mysql服务
    1.从服务器下载最新的版本https://downloads.mysql.com/archives/community/ 2.解压到本地文件 3.配置系统变量MYSQL_HOME值是本地的地址D:\Program\mysql-8.0.......
  • 7:数据库设计思维-MySQL
    (目录)7.1数据库设计的基本概要表结构就是定义数据表文件名,确定数据表包含哪些字段,各字段的字段名、字段类型、及宽度,并将这些数据输入到计算机当中关系型数据库:两张表......
  • mysql 8.0 递归实现菜单树
    mysql8.0递归实现菜单树WITHrecursiverec_menu(id,menu_id,sup_menu,menu_name,`level`,rownum,order_str)AS(SELECTT0.id,T0.menu_id,T0.sup_menu,T0.......
  • ADO.NET连接MySQL注意细节
    Nuget安装MySQL包MySql.Data.MySqlClient几个数据库对象的前缀为:MySQL比如:MySqlConnection连接字符串可以参考这里:https://www.cnblogs.com/cqpanda/p/16316311.......
  • MySQL
    MySQL及SQL注入如果您通过网页获取用户输入的数据并将其插入一个MySQL数据库,那么就有可能发生SQL注入安全的问题。本章节将为大家介绍如何防止SQL注入,并通过脚本来过滤S......
  • mysql数据库一些实用的东西
    -------------------------------数据库的锁粒度篇---------------------------------------------首先我们有一张数据表,三个字段id,name,age,val。id是主键,name是索引,info......
  • MySQL Workbench的安装
    1.下载MySQLWorkbench下载MySQLWorkbench2.安装步骤-下载MySQLWorkbench的msi包-安装过程-更改安装路径-安装成功-登录数据库-进入数据库-......