thinkphp 查询数据库数据根据两个字段group,且统计条数用法

$result=M('sale_lead')
    ->field('lead_source,created_by,count(sale_lead_id ) as count_num')
    ->group('lead_source,created_by')
    ->where($where)
    ->select();


 
 
结果:
array(14) {
  [0] => array(3) {
    ["lead_source"] => string(1) "1"
    ["created_by"] => string(2) "42"
    ["count_num"] => string(1) "1"
  }
  [1] => array(3) {
    ["lead_source"] => string(1) "3"
    ["created_by"] => string(2) "43"
    ["count_num"] => string(1) "1"
  }
  [2] => array(3) {
    ["lead_source"] => string(1) "4"
    ["created_by"] => string(2) "29"
    ["count_num"] => string(1) "2"
  }
  [3] => array(3) {
    ["lead_source"] => string(1) "5"
    ["created_by"] => string(2) "29"
    ["count_num"] => string(1) "1"
  }
  [4] => array(3) {
    ["lead_source"] => string(1) "5"
    ["created_by"] => string(2) "42"
    ["count_num"] => string(1) "1"
  }
  [5] => array(3) {
    ["lead_source"] => string(1) "6"
    ["created_by"] => string(2) "29"
    ["count_num"] => string(1) "2"
  }
  [6] => array(3) {
    ["lead_source"] => string(1) "7"
    ["created_by"] => string(2) "42"
    ["count_num"] => string(1) "1"
  }
  [7] => array(3) {
    ["lead_source"] => string(1) "7"
    ["created_by"] => string(2) "43"
    ["count_num"] => string(1) "2"
  }
  [8] => array(3) {
    ["lead_source"] => string(1) "8"
    ["created_by"] => string(2) "42"
    ["count_num"] => string(1) "5"
  }
  [9] => array(3) {
    ["lead_source"] => string(1) "8"
    ["created_by"] => string(2) "43"
    ["count_num"] => string(1) "2"
  }
  [10] => array(3) {
    ["lead_source"] => string(2) "13"
    ["created_by"] => string(2) "43"
    ["count_num"] => string(1) "1"
  }
  [11] => array(3) {
    ["lead_source"] => string(2) "43"
    ["created_by"] => string(2) "43"
    ["count_num"] => string(1) "2"
  }
  [12] => array(3) {
    ["lead_source"] => string(2) "44"
    ["created_by"] => string(2) "43"
    ["count_num"] => string(1) "1"
  }
  [13] => array(3) {
    ["lead_source"] => string(2) "45"
    ["created_by"] => string(2) "43"
    ["count_num"] => string(1) "1"
  }
}

 
 

                
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值