欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

TP中统计指定字段的总数

程序员文章站 2022-06-22 10:48:32
如统计已激活设备数量和未激活设备数量 $condition = [ ['member_id', '=', $member_id] ]; $field = [ 'COUNT(IF(active_member_id > 0, 1, null)) as actived_num', 'COUNT(IF(ac ......

如统计已激活设备数量和未激活设备数量

$condition = [
    ['member_id', '=', $member_id]
];
$field = [
    'count(if(active_member_id > 0, 1, null)) as actived_num',
    'count(if(active_member_id = 0, 1, null)) as unactived_num',
];

$list = $this->where($where)->field($field)->order($order)->select();