php数据库最大值 php数据库最大值是多少

mysql和PHP如何找到数据库中的最大值?

?php  

成都创新互联公司10多年成都企业网站定制服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都企业网站定制及推广,对成都服务器托管等多个行业拥有丰富的网站营销经验的网站建设公司。

//连接数据库  

$myconn=mysql_connect("localhost","root","");  

mysql_select_db("nowamagic",$myconn);  

$strSql="

select article_ID

from article

where article_ID=(select max(article_ID)

from article)

";

$strSql2="

select article_ID

from article

where article_ID=(select min(article_ID)

from article)

";

 

$result=mysql_query($strSql,$myconn) or die(mysql_error());  

$result2=mysql_query($strSql2,$myconn) or die(mysql_error());

$row_max=mysql_fetch_array($result);

$row_min=mysql_fetch_array($result2);

// 输出ID最大值

//echo $row_max["article_ID"];

//echo "

";

// 输出ID最小值

//echo $row_min["article_ID"];

$article_count = $row_max["article_ID"] - $row_min["article_ID"];

?

thinkPHP 如何查询出数据库中id最大的一条数据?

thinkPHP 查询数据库中id最大的一条数据操作如下:

先给数据库中的这个字段(sort)分组 再降序排列, 取第1条。

通过步骤1 获取了 sort值为最大的数据, 然后在 通过 where sort ='步骤1取的值'。

查询最大ID,select max(id) from table。

查询最大ID的记录 select * from table where id = (select max(id) from table)

或者select * from table t where  not exists (select 1 from table t1 where t1.id t.id)

PHP技术 获取数据库中某个字段的最大值(int类型)并将获得的最大值与另一个值比较大小

select case

when a.maxnum 另一个值 then a.maxnum+1

when a.maxnum 另一个值 then 另一个值

end

from ( select max(字段) as maxnum from table) a

只能在php中查出来


标题名称:php数据库最大值 php数据库最大值是多少
标题网址:http://pwwzsj.com/article/ddoghpo.html