加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

thinkphp中使用group by时候如何用sum?

(2016-07-10 21:14:52)
标签:

php

thinkphp

分类: thinkphp
thinkphp中使用group by时候如何用sum?

示例代码:
$reinfo=M("comreceiveinfo");
            $relist=$reinfo->where("userid='".$_SESSION["username"]."'")->select();
            $this->assign("relist",$relist);
            $shopcart=M("shoppingcart");
            $groupcart=$shopcart->field('supid,sum(shopprice) as sspp,sum(pv) as sspv')->where("agentd='".$_SESSION["username"]."'")->group("supid")->select();
            $pricetotal=0;
            $counttotal=0;
            $pvtotal=0;
            foreach($groupcart as $n=>$val){
                $groupcart[$n]["voo"]=$shopcart->where("supid=".$val["supid"])->select();
                $pricetotal=$pricetotal+$val["sspp"];
                $pvtotal=$pvtotal+$val["sspv"];
                $counttotal=$counttotal+count($groupcart[$n]["voo"]);
            }
            $this->assign("groupcart",$groupcart);
            $this->assign("pricetotal",$pricetotal);
            $this->assign("pvtotal",$pvtotal);
            $this->assign("counttotal",$counttotal);
            $this->display();   

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有