在这种情况下,建议的方法是对数据库中的数据进行排序,在
ORDER BY获取结果的查询末尾添加一个,如下所示:
SELECt temperature FROM temperatures ORDER BY temperature ASC; -- ascending orderSELECt temperature FROM temperatures ORDER BY temperature DESC; -- descending order
如果由于某种原因不是可选项,则可以在Python中更改排序顺序,如下所示:
templist = [25, 50, 100, 150, 200, 250, 300, 33]sorted(templist, key=int) # ascending order> [25, 33, 50, 100, 150, 200, 250, 300]sorted(templist, key=int, reverse=True) # descending order> [300, 250, 200, 150, 100, 50, 33, 25]
正如评论中指出的那样,如果接收到的数据类型为,则需要
int键(或
float是否存储带小数的值)来正确地对数据进行排序
string,但是如果将温度值存储为字符串,则很奇怪在这种情况下,请返回并从根本上解决问题,并确保所存储的温度是数字。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)