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;
}
原文地址:https://www.cnblogs.com/xm666/p/11201118.html