dongluoqiu0255 2014-10-05 18:26
浏览 8
已采纳

如何在cakephp中实现“有案例时”

Cake php code -

$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'));

It's mysql query

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

how to implement below this section in above cake php code

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

in cake php

  • 写回答

1条回答 默认 最新

  • douwei4370 2014-10-06 11:10
    关注

    Implement “having sum case when” in 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'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示