?php
我们提供的服务有:成都网站制作、做网站、微信公众号开发、网站优化、网站认证、东兴ssl等。为成百上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的东兴网站制作公司
//连接数据库
$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"];
?
SELECT * from PTest WHERE PCode=(SELECT min(PCode) FROM PTest WHERE PCount=(SELECT min(PCount) from PTest))
: select max(date) from ( select max(date) date from A unoin all select max(date) date from B ) a
最大值:select max(num) from table
第二大值:select max(num) from table
where num not in(select max(num) from table)
第三大值:select max(num) from table
where num not in(select max(num) from table
where num not in(select max(num) from table))
最小值:select min(num) from table
SELECT * FROM 表名 WHERE (球队id,总得分) IN (SELECT 球队id,MIN(总得分) FROM 表名 GROUP BY 球队id);
使用聚合函数min()求最小值,对应max()求最大值。
SELECT roomID FROM room WHERE guestNumber = (SELECT MIN(guestNumber) FROM room)