简体   繁体   English

如何从MySQL表PHP中获取最高的整数值

[英]how to get highest integer value from mysql table PHP

how to get highest integer value from mysql table PHP 如何从MySQL表PHP中获取最高的整数值

   $getingstoredata=mysql_query('select number from number ');

   while ($getstd=mysql_fetch_row($getingstoredata)){

   print_r($getstd);
                                                    }

and table stricture is same like this image http://fastcoding.tk/table.png 和表的狭窄是一样的,就像这张图片http://fastcoding.tk/table.png

i want to display highest integer value for example it 120 is highest value in this table 我想显示最高整数值,例如120是此表中的最高值

使用MAX()

SELECT MAX(number) FROM number

You can simply use the Aggregate Functions. 您可以简单地使用聚合函数。 SELECT MAX(field_name) FROM table_name GROUP BY field_name; SELECT MAX(field_name)FROM table_name GROUP BY field_name;

You can also use "order by" clause with DESC and fetch the first row from result-set. 您还可以在DESC中使用“ order by”子句,并从结果集中获取第一行。

select MAX(number) from number;

MAX()应该满足您的目的

If your field is a mixed varchar where some values begin with letters, you can use this solution: 如果您的字段是混合varchar ,其中某些值以字母开头,则可以使用以下解决方案:

SELECT max(number) FROM table WHERE number REGEXP '^[0-9]+$';
  1. the function max() will take the highest value 函数max()将取最大值
  2. the regex sorts out every value that not begins with a number 正则表达式会筛选出所有不以数字开头的值
$hinteger=mysql_query("SELECT MAX(integer) FROM number");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM