Loading

mysql order by的应用

$sql = "select *from goods order by price desc";

order by 按 price 排序

 

查找所有品牌的平均值,然后按平均值由高到低排序品牌和价格字段.

//group by和order by可以并用
$sql = "select brand,count(*),avg(price) from goods group by brand order by avg(price) desc";
$result = mysqli_query($link,$sql);
if(mysqli_num_rows($result)>0)
{
    while($row = mysqli_fetch_assoc($result))
    {
        echo '价格是:'.$row['brand'],$row['avg(price)'],'<br>';
    }
}
else
{
    echo '错误';
    exit;
}

 

posted @ 2019-07-17 15:04  mingBolg  阅读(128)  评论(0编辑  收藏  举报