0

我有 sql 代码,我想用 cake php 做,但我不知道怎么做,我不想那样做

$obj->查询($sql);
这是我的查询:

“选择 dbfiles.amount, MONTHNAME(cases.enquiry_date) 作为 Month FROM cases
   INNER JOIN services ON cases.id = services.case_id
   INNER JOIN dbfiles ON services.id = dbfiles.service_id
   WHERE case.status = 2 AND YEAR(cases.enquiry_date) = '2012' AND dbfiles.type = 'INV'
   AND case.currency = 'EUR' GROUP BY dbfiles.invoice_num ORDER BY Month DESC; "
   

4

1 回答 1

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)
)
于 2012-05-10T08:34:17.623 回答