mysql count max min 语句用法

时间:2022-04-13 14:18:24

count 用法 求总条数

$sql="select count(*) as total from e_user";
$query = mysql_query($sql, $link);
$res = mysql_fetch_array($query);
$count = $res['total'];

max用法

$sql="select max(id) as maxid from e_user";
$sql="select id as maxid from e_user order by id desc limit 0,1";

min用法

$sql="select min(id) as minid from e_user";
$sql="select id as minid from e_user order by id desc limit 0,1";

sum 用法 求总和

$sql="select sum(id) as total from e_user";

AVG 用法 求平均值

$sql="select avg(id) as total from e_user";