如統計已激活設備數量和未激活設備數量this
$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();