Php 如何实施";有“和”的情况;卡克菲普

Php 如何实施";有“和”的情况;卡克菲普,php,mysql,cakephp,cakephp-2.0,cakephp-2.1,Php,Mysql,Cakephp,Cakephp 2.0,Cakephp 2.1,蛋糕php代码- $this->paginate = array( 'Lead' => array( 'joins'=>array( array( 'type'=>'left', 'table'=>'lead_countries', 'alias'=>'LeadCountry',

蛋糕php代码-

$this->paginate = array(
    'Lead' => array(
        'joins'=>array(
                array(
                    'type'=>'left',
                    'table'=>'lead_countries',
                    'alias'=>'LeadCountry',
                    'conditions'=>array(
                        'LeadCountry.lead_id = Lead.id',
                    ),

                )
            ),
        'conditions' => $conditions,
        'order' => array('LeadCountry.lead_id' => 'DESC'),
        'group' => array('LeadCountry.lead_id'), //fields to GROUP BY               
        'limit' => $per_page
    )
);
$leads = $this->Paginator->paginate('Lead');
$this->set(compact('leads'));
这是mysql查询

SELECT `Lead`.`id` , `LeadCountry`.`primary_email` , `LeadCountry`.`first_name` , `LeadCountry`.`lead_id` , `LeadCountry`.`id`
FROM `leads` AS `Lead`
INNER JOIN `ekowarehouse`.`lead_countries` AS `LeadCountry` ON ( `LeadCountry`.`lead_id` = `Lead`.`id` )
GROUP BY `Lead`.`id`
HAVING sum(
CASE WHEN `LeadCountry`.`active` <>0
THEN 1
ELSE 0
END ) =0
选择'Lead`.'id`、'LeadCountry`.'primary\u email`、'LeadCountry`.'first\u name`、'LeadCountry`.'Lead\u id`、'LeadCountry`.'id``
从'leads'变为'Lead`
在(`LeadCountry`.`lead\u id`=`lead`.`id`)上将`ekowarehouse`.`lead\u countries`作为`LeadCountry`的内部联接
按“Lead”分组。`id`
有总和(
“LeadCountry”时的大小写。“active”0
那么1
其他0
结束)=0
如何在上面的php代码中实现下面这一部分

HAVING sum(
CASE WHEN `LeadCountry`.`active` <>0
THEN 1
ELSE 0
END ) =0
有总和的( “LeadCountry”时的大小写。“active”0 那么1 其他0 结束)=0
在cake php中

在cakephp中实现“有sum case when”

$this->paginate = array(
    'Lead' => array(
        'joins'=>array(
                array(
                    'type'=>'left',
                    'table'=>'lead_countries',
                    'alias'=>'LeadCountry',
                    'conditions'=>array(
                        'LeadCountry.lead_id = Lead.id',
                    ),

                )
            ),
        'conditions' => $conditions,
        'order' => array('LeadCountry.lead_id' => 'DESC'),
        //'group' => array('LeadCountry.LeadCountry'), //fields to GROUP BY
        'group' => '`LeadCountry`.`LeadCountry` HAVING sum(case when `LeadCountry`.`active` <> 0 then 1 else 0 end) = 0', //fields to GROUP BY              
        'limit' => $per_page
    )
);
$leads = $this->Paginator->paginate('Lead');
$this->set(compact('leads'));
$this->paginate=array(
“Lead”=>数组(
'连接'=>数组(
排列(
'type'=>'left',
“表”=>“领先国家”,
'别名'=>'领先国家',
“条件”=>数组(
'LeadCountry.lead_id=lead.id',
),
)
),
“条件”=>$conditions,
'order'=>array('LeadCountry.lead\u id'=>'DESC'),
//'group'=>array('LeadCountry.LeadCountry'),//要分组的字段
'group'=>''LeadCountry`.'LeadCountry`具有总和(当'LeadCountry`.'active'0然后1 else 0 end=0'时为大小写),//要分组的字段
“限制”=>每页$
)
);
$leads=$this->Paginator->paginate('Lead');
$this->set(紧凑型('leads');