2014-10-05 67 views
0

蛋糕PHP代碼 -如何實現 「有總和情況下,當」 CakePHP中

$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 

如何實現低於上述蛋糕PHP代碼本節

HAVING sum(
CASE WHEN `LeadCountry`.`active` <>0 
THEN 1 
ELSE 0 
END) =0 

in cake php

回答

0

在cakephp中執行「有總結案例」

$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')); 
相關問題