您可以借助汇总函数MAX在列中找到最高编号。语法如下-
select max(yourColumnName) as anyVariableName from yourTableName;
为了理解上述概念,让我们创建一个带有int列的表。以下是创建表的查询。
mysql> create table HighestNumberDemo −> ( −> BigNumber int −> );
现在,在表中插入一些值。插入记录的查询如下-
mysql> insert into HighestNumberDemo values(1234); mysql> insert into HighestNumberDemo values(9999); mysql> insert into HighestNumberDemo values(10000); mysql> insert into HighestNumberDemo values(989898); mysql> insert into HighestNumberDemo values(999987);
现在,您可以在select语句的帮助下显示所有记录。显示所有记录的查询如下-
mysql> select *from HighestNumberDemo;
以下是输出-
+-----------+ | BigNumber | +-----------+ | 1234 | | 9999 | | 10000 | | 989898 | | 999987 | +-----------+ 5 rows in set (0.00 sec)
实现我们上面讨论的语法以在列中找到最大的数字。查询如下-
mysql> select max(BigNumber) as HighestNumber from HighestNumberDemo;
以下是输出-
+---------------+ | HighestNumber | +---------------+ | 999987 | +---------------+ 1 row in set (0.00 sec)