数据库:
1.一个条件分组查询
$sql = "select brand,count(*),sum(price),avg(price),max(price),min(price) from goods group by brand"; $result = mysqli_query($link,$sql); if(mysqli_num_rows($result)>0) { while($row = mysqli_fetch_assoc($result)) { echo ‘品牌有‘.$row[‘brand‘],‘品牌的数量是‘.$row[‘count(*)‘].‘价格的总和是‘.$row[‘sum(price)‘].‘ 平均值是‘.$row[‘avg(price)‘].‘最大值是‘.$row[‘max(price)‘]. ‘最小值是‘.$row[‘min(price)‘].‘<br>‘; } } else { echo ‘错误‘; exit; }
2.二个条件分组查询
//多条件分组group by $sql = "select brand,pro_adds,count(*) from goods group by brand,pro_adds"; $result = mysqli_query($link,$sql); if(mysqli_num_rows($result)>0) { while($row = mysqli_fetch_assoc($result)) { echo $row[‘brand‘],$row[‘pro_adds‘],$row[‘count(*)‘].‘<br>‘; } } else { echo ‘错误‘; exit; }
原文地址:https://www.cnblogs.com/xm666/p/11200166.html
时间: 2024-10-21 10:34:35