Python MySQL Order By
章节
对结果排序
可以使用ORDER BY语句,按升序或降序对结果排序。
默认情况下,ORDER BY关键字按升序排列结果。要按降序排列,可使用DESC关键字。
示例
按name
的字母顺序排列结果:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="你的用户名",
passwd="你的密码",
database="mydatabase"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM customers ORDER BY name"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
ORDER BY DESC
使用DESC关键字,可按降序对结果排序。
示例
按name
的字母降序,对结果进行排序:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="你的用户名",
passwd="你的密码",
database="mydatabase"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM customers ORDER BY name DESC"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
Python MySQL Order By的更多相关文章
- Python MySQL Join
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL Update
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL Limit
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL 删除表
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL Delete
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL Where
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL Select
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL 创建表
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
- Python MySQL 插入表
章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...
随机推荐
- SpringMVC的@ControllerAdvice注解
@ControllerAdvice顾名思义,他是一个Controller的增强,是一个异常处理类.常用于实现下面三个方面的功能: 1.处理全局异常,结合方法型注解@ExceptionHandler,用 ...
- java并发:初探sleep方法
sleep与wait sleep是Thread方法,使得当前线程从运行态变为阻塞态.但它不会释放对象的锁. wait方法是Object方法,它的作用是使得当前拥有对象锁的线程从运行态变为阻塞态, 它会 ...
- #define 和 const
来自:牛客网参考解析 1.const定义常量是有数据类型的,而#define宏定义常量却没有2.const常量有数据类型,而宏常量没有数据类型.编译器可以对const进行类型安全检查, 而对后者只 ...
- 第1节 storm编程:3、storm的架构模型的介绍
nimbus:主节点,接收客户端提交的任务,并且分配任务,新的版本当中nimbus已经可以有多个了 zookeeper集群:storm依靠zk来保存一些节点信息,nimbus将分配的任务信息都写入到z ...
- 「CF1039D」You Are Given a Tree
传送门 Luogu 解题思路 整体二分. 的确是很难看出来,但是你可以发现输出的答案都是一些可以被看作是关键字处于 \([1, n]\) 的询问,而答案的范围又很显然是 \([0, n]\),这不就刚 ...
- pgsql 查询jsonb中包含某个键值对的表记录
pgsql 查询jsonb中包含某个键值对的表记录 表名 table_name ,字段 combos 类型为 jsonb 可为空,示例内容如下, $arr_combos = [ ['id' => ...
- 小程序通过web-view实现与h5页面之间的交互
在小程序端使用web-view内嵌网页,通过 src 携带参数,通过 @message 接收h5传回的数据 <template> <view> <web-view :sr ...
- CentOS 7 搭建本地YUM仓库,并定期同步阿里云源
目录导航: 1. 系统环境 2. 修改yum 源为阿里云源 3. 安装yum相关的软件 4. 根据源标识同步源到本地目录 5. 安装nginx开启目录权限保证本地机器可以直接本地yum源 6. 客户端 ...
- Linux分发版本的试用及选择工具
https://www.forbes.com/sites/jasonevangelho/2019/06/15/how-to-test-drive-200-linux-distributions-wit ...
- 在html中创建自定义标签
创建并使用自定义标签 Web Components 标准非常重要的一个特性是,它使开发者能够将HTML页面的功能封装为 custom elements(自定义标签),本篇介绍使用 CustomElem ...