为此,您需要将varchar值强制转换为INTEGER。
让我们首先创建一个表-mysql> create table DemoTable765 (ItemPrice varchar(200));
使用插入命令在表中插入一些记录-mysql> insert into DemoTable765 values('567.00');
mysql> insert into DemoTable765 values('1089.00');
mysql> insert into DemoTable765 values('540.00');
mysql> insert into DemoTable765 values('788.00');
使用select语句显示表中的所有记录-mysql> select *from DemoTable765;
这将产生以下输出-+-----------+
| ItemPrice |
+-----------+
| 567.00 |
| 1089.00 |
| 540.00 |
| 788.00 |
+-----------+
4 rows in set (0.00 sec)
以下是显示带有数字的字符串的最大值的查询。我们曾经CAST()将其强制转换为INTEGER-mysql> select *from DemoTable765 order by cast(ItemPrice AS SIGNED INTEGER) DESC;
这将产生以下输出-+-----------+
| ItemPrice |
+-----------+
| 1089.00 |
| 788.00 |
| 567.00 |
| 540.00 |
+-----------+
4 rows in set, 4 warnings (0.00 sec)