此问题在此处已有答案:
SQL order string as number(11个答案)
3天前关闭.
qry = "SELECT * FROM courses ORDER BY price DESC "
在这里,出于逻辑原因,我将price声明为varchar,因此在排序的情况下,它给出
输出:
{
"id": 5,
"payment_type": "one time",
"price": "1000"
},
{
"id": 11,
"payment_type": "one time", # issue here
"price": "10000"
},
{
"id": 10,
"payment_type": "Lumpsum", # issue here
"price": "12000"
},
{
"id": 2,
"payment_type": "one time",
"price": "3000"
},
{
"id": 13,
"payment_type": "one time",
"price": "3500"
},
{
"id": 12,
"payment_type": "one time",
"price": "4500"
},
....等等
我可以订购这个价格而不改变这个列的数据类型吗?
SET:试图获取的列“varchar”的类型:按价格ASC或DESC订购
1条答案
按热度按时间qni6mghb1#
你试图在字符串上使用ORDER BY,所以它试图按词法排序,一个解决方案是转换类型:SELECT * FROM课程按角色排序('价格'为小数)DESC;
希望能成功!