问题
can someone help me, and show me how to insert BEETWEN in having clausule in cakephp
exampleo of my codE:
$zaduzenja = $this->Zaduzenja->find('all',array(
'conditions' => array(
'Zaduzenja.placeno' => 0 ),
'fields' => array('Zaduzenja.obveznici_id', 'SUM(Zaduzenja.zaduzenje) as dug'),
'group' => 'Zaduzenja.obveznici_id HAVING array(dug BETWEEN ? AND ? => array('.$iznosOd,$iznosDo)'
));
but this not working, i only want Calculated column "dug" to check if Dug >=$temp 1 AND Dug <=$temp2, but this is posible only in group with having clausule
回答1:
why not simply this?
$db = $this->Zaduzenja->getDataSource();
$iznosOd = $db->value($iznosOd, 'double'); // quotes and escapes input to avoid SQL injections
$iznosDo = $db->value($iznosDo, 'double'); // ditto
$zaduzenja = $this->Zaduzenja->find(
'all',
array(
'conditions' => array(
'Zaduzenja.placeno' => 0
),
'fields' => array(
'Zaduzenja.obveznici_id',
'SUM(Zaduzenja.zaduzenje) as dug'
),
'group' => "Zaduzenja.obveznici_id HAVING dug BETWEEN $iznosOd AND $iznosDo"
)
);
回答2:
Hi change your query as shown below:
$zaduzenja = $this->Zaduzenja->find('all',array(
'conditions' => array(
'Zaduzenja.placeno' => 0
),
'fields' => array(
'Zaduzenja.obveznici_id',
'SUM(Zaduzenja.zaduzenje) as dug'
),
'group' => 'Zaduzenja.obveznici_id having dug Between '.$temp_1.' and '.$temp2
));
Iinjoy
来源:https://stackoverflow.com/questions/20797240/cakephp-having-condition-in-find