要从最大值到最小值排序,请使用ORDER BY length()。让我们首先创建一个表-create table DemoTable
-> (
-> Price varchar(20)
-> );
使用插入命令在表中插入一些记录-insert into DemoTable values('80');
insert into DemoTable values('800');
insert into DemoTable values('108');
insert into DemoTable values('765');
使用select语句显示表中的所有记录-select *from DemoTable;
这将产生以下输出-+-------+
| Price |
+-------+
| 80 |
| 800 |
| 108 |
| 765 |
+-------+
4 rows in set (0.00 sec)
这是在MySQL中将最大到最小排序的查询-select *from DemoTable
-> order by length(Price) DESC,Price DESC;
这将产生以下输出-+-------+
| Price |
+-------+
| 800 |
| 765 |
| 108 |
| 80 |
+-------+
4 rows in set (0.00 sec)