Home > Database > Mysql Tutorial > mysql筛选GROUP BY多个字段组合时的用法分享

mysql筛选GROUP BY多个字段组合时的用法分享

WBOY
Release: 2016-06-07 18:03:27
Original
1183 people have browsed it

mysql筛选GROUP BY多个字段组合时的用法分享,需要的朋友可以参考下。

想实现这样一种效果

如果使用group by一个条件的话,得到的结果会少了很多,如何多个条件组合筛选呢
代码如下:
group by fielda,fieldb,fieldc...

循环的时候可以通过判断后一个跟前面一个是否相同来分组,一个示例
代码如下:
$result = mysql_query("SELECT groups,name,goods FROM table GROUP BY groups,name ORDER BY name");
$arr = array();
$i = 0;
while($row = mysql_fetch_array($result)){
$arr[] = $row;
}

$m = $i - 1;
foreach($arr as $k=>$v){
if($v[$i]['groups'] $v[$m]['groups']){
echo '分割符号';
}
echo $v['name'],$v['goods'];
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template