最大数量计算错误

时间:2014-08-14 10:36:04

标签: php mysql

patient_id:1,2,3,4,5,6,7,8,9,10

 $result2=mysql_query("select max(patient_id) as maximum from outdoor");
        $row2= mysql_fetch_array($result2);
      echo $res=$row2['maximum'];

最大数量为9而不是10。

2 个答案:

答案 0 :(得分:1)

试试这个

$sql = "select max(CONVERT(patient_id,UNSIGNED INTEGER)) as maximum from outdoor";

答案 1 :(得分:0)

使用此

$sql = "select GREATEST(patient_id) as maximum from outdoor";

使用GREATEST()

例如:

SELECT GREATEST(2,1);