sql server 在thinkphp中将查询结果分组显示并统计相同结果的数量 5C

有三张表
1. 图片说明

将查询结果以商品分组,将每样商品的评价个数统计出来并计算商品分数,样式如下
1. 图片说明

自己在thinkphp里面写的代码如下,group里面的字段老是报错,统计结果也不对

 $model = M('rkdb');
$field = array('a.time,a.pid,a.evaluate,b.name,c.name,c.gg');
$list = $model
            ->alias('a')
            ->join('__GYSB__ as b on b.no=a.gid','LEFT')
            ->join('__SPB__ as c on a.pid=c.no')
            ->group('a.pid')
            ->field($field)
            ->select();
                        foreach($list as $value){
            //获取所有评价的次数
            //好
            $onecount = M('rkdb')->where(array('no'=>$value['no'],'pingjia'=>'好'))->count();
            $value['onelevel'] =!$onecount?0:$onecount;
            //较好
            $twocount =  M('rkdb')->where(array('no'=>$value['no'],'pingjia'=>'较好'))->count();
            $value['twolevel'] = !$twocount?0:$twocount;
            //一般
            $threecount =  M('rkdb')->where(array('no'=>$value['no'],'pingjia'=>'一般'))->count();
            $value['threelevel'] = !$threecount?0:$threecount;
            //差
            $fourcount =  M('rkdb')->where(array('no'=>$value['no'],'pingjia'=>'差'))->count();
            $value['forulevel'] = $fourcount;
            //获取总分
            $value['totalcount'] = ($onecount*5)+($twocount*4)+($threecount*3)+($fourcount*4);
            $array[]=$value;

如上,该怎么对查询数据进行分组并统计 评价个数以及 总分呢

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐