让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Value varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('20'); mysql> insert into DemoTable values('10.5'); mysql> insert into DemoTable values('11'); mysql> insert into DemoTable values('10'); mysql> insert into DemoTable values('20.5');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+ | Value | +-------+ | 20 | | 10.5 | | 11 | | 10 | | 20.5 | +-------+ 5 rows in set (0.00 sec)
这是查询以点对MySQL中的项目进行排序-
mysql> select *from DemoTable -> order by CAST(Value AS DECIMAL) ASC;
这将产生以下输出-
+-------+ | Value | +-------+ | 10 | | 10.5 | | 11 | | 20 | | 20.5 | +-------+ 5 rows in set (0.00 sec)