select campaign,lead_status,COUNT(id)
from buyers
where lead_status IN('Very Hot','Hot', 'Warm', 'Cold', 'Not Contacted')
and campaign IN('stage1','stage2','stage3','stage4') and created_on >='2012-10-01'
and is_put_for_exchange='0' and transaction_type='First Sale'
and propertytype='Residential'
group by campaign,lead_status
ORDER BY campaign asc, field(lead_status,'Very Hot','Hot', 'Warm', 'Cold', 'Not Contacted')
转换为cakephp语法plz It Argent?
答案 0 :(得分:7)
您可以通过documentation。
将原始SQL修改为CakePHP格式或者由于任何原因你不能/不会,那么你可以使用原始SQL查询,如下所示:
在控制器中:
$this->ModelName->query('SELECT * FROM table');
在模型中:
$this->query('SELECT * FROM table');
答案 1 :(得分:6)
试试这个
$this->Buyer->find('all', array(
'fields' => $arrayOfFields,
'conditions' => array(
'Buyer.lead_status' => $arrayOfLeadStatus,
'Buyer.compaign' => $arrayOfCompaign,
'Buyer.is_put_for_exchange' => 0,
'Buyer.transaction_type' => 'First Sale',
'Buyer.propertytype' => 'Residential'
),
'group' => array('Buyer.campaign','Buyer.lead_status'),
'order' => 'Buyer.campaign'
));
答案 2 :(得分:0)
供他人参考,如果我们转换为cakephp方法,则该查询将类似于此
$result = $this->ModelName->find("all",array(
'fields' => array('campaign','lead_status','count(id') as counts),
'conditions' => array(
'lead_status' => array('Very Hot','Hot', 'Warm', 'Cold', 'Not Contacted'),
'campaign' => array('stage1','stage2','stage3','stage4'),
"created_on >='2012-10-01' ",
'is_put_for_exchange' => 0,
'transaction_type' => 'First Sale',
'propertytype' => 'Residential'
),
'group' => array('Buyer.campaign','Buyer.lead_status'),
'order' => 'Buyer.campaign'
));