【发布时间】:2020-06-13 06:21:36
【问题描述】:
我是 SQL 初学者。
考虑一下我的简单代码:
cnx = mysql.connector.connect(user='root', password='',
host='127.0.0.1', database='employees')
cursor = cnx.cursor()
cursor.execute('SELECT * FROM people ORDER BY Height DESC, Weight')
my_result = cursor.fetchall()
cnx.close()
for x in my_result:
print(x[0], x[1], x[2])
我的 employees 数据库中有一个 people 表,其中包含 name、Height 和 Weight 列。如果我运行此代码,它会打印所需的排序并且没有问题。但是,似乎这段代码本质上并没有改变表的行顺序。我的意思是,现在如果我跑
SELECT * FROM people;
在终端我得到后一个表(没有所需的顺序)。现在,我的问题是:
如何更改表格的顺序以使用 Python 获得具有所需排序的新表格?有可能吗?
谢谢。
【问题讨论】:
标签: python mysql mysql-python