Vik*_*ale 2 mysql cakephp converter
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')
Run Code Online (Sandbox Code Playgroud)
转换为cakephp语法plz It Argent?
小智 8
您可以通过阅读文档将原始SQL修改为CakePHP格式.
或者由于任何原因你不能/不会,那么你可以使用原始SQL查询,如下所示:
在控制器中:
$this->ModelName->query('SELECT * FROM table');
Run Code Online (Sandbox Code Playgroud)
在模型中:
$this->query('SELECT * FROM table');
Run Code Online (Sandbox Code Playgroud)
试试这个
$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'
));
Run Code Online (Sandbox Code Playgroud)