我有sql代码,我想在蛋糕php做,但我不知道如何,我不想这样做
$obj->query($sql);这是我的问题:
"SELECT dbfiles.amount, MONTHNAME(cases.enquiry_date) as Month FROM cases INNER JOIN services ON cases.id = services.case_id INNER JOIN dbfiles ON services.id = dbfiles.service_id WHERE cases.status = 2 AND YEAR(cases.enquiry_date) = '2012' AND dbfiles.type = 'INV' AND cases.currency = 'EUR' GROUP BY dbfiles.invoice_num ORDER BY Month DESC; "
答案 0 :(得分:0)
假设$ obj属于班级Case
$obj->find('all', array(
'fields' => array('dbfiles.amount', 'MONTHNAME(cases.enquiry_date) as MONTH',
'joins' => array(
array(
'table' => 'services',
'type' => 'INNER',
'conditions' => array('cases.id = services.case_id'),
'foreignKey' => false
),
array(
'table' => 'dbfiles',
'type' => 'INNER',
'conditions' => array('services.id = dbfiles.service_id'),
'foreignKey' => false
)
),
'conditions' => array('cases.status' => 2, ... the rest of your WHERE clauses)
)