php having必须与group by一起使用才可以,前面可以加where条件

$sql = "select brand,count(*),avg(price) from goods where price>3500 group by brand having avg(price)>2000";   //红线的where是扩展加上去的,加了where条件范围更小了
$result = mysqli_query($link,$sql);
if(mysqli_num_rows($result)>0)
{
    while($row = mysqli_fetch_assoc($result))
    {
        echo $row['brand'],'平均值:'.$row['avg(price)'],'总数'.$row['count(*)'].'<br>';
    }
}
else
{
    echo '错误';
    exit;
}

having其实相当于where的作用