让我们首先创建一个表-
create table DemoTable ( Value varchar(100) );
使用插入命令在表中插入一些记录-
insert into DemoTable values('190'); insert into DemoTable values('230'); insert into DemoTable values('120'); insert into DemoTable values('189');
使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+-------+ | Value | +-------+ | 190 | | 230 | | 120 | | 189 | +-------+ 4 rows in set (0.00 sec)
以下是从VARCHAR列获取最小值和最大值并在单独的MySQL列中显示结果的查询-
select min(cast(Value AS SIGNED)) AS Min, max(cast(Value AS SIGNED)) AS Max from DemoTable;
这将产生以下输出-
+------+------+ | Min | Max | +------+------+ | 120 | 230 | +------+------+ 1 row in set (0.03 sec)