在Zend \ Db \ Sql \ Select中无法使用sql生成语句

时间:2016-06-08 05:49:56

标签: php mysql select zend-framework2 having-clause

我试图用HAVING子句获取数据。

这是我的代码,

List<Integer> listOfNumbers = new LinkedList<>(Arrays.asList(1, 2, 4, 5, 3, 6));
int twoIndex = listOfNumbers.indexOf(2);
int threeIndex = listOfNumbers.indexOf(3);
listOfNumbers.set(twoIndex, 3);
listOfNumbers.set(threeIndex, 2);

这为我提供了正确的查询。在//Main Table $select->from(array('cre' => 'credit')); //company Table $select->join(array('com' => 'company), 'cre.account_id = com.account_id'); $select->join(array('u' => 'user'), 'cre.approved_by = u.id', array('first_name', 'last_name'), 'left'); $select->join(array('acc' => 'account'), 'cre.account_id = acc.id', array('id'), 'left'); $startDate = \DateTime::createFromFormat('d-m-Y H:i:s', $startDate.' 00:00:00')->format('Y-m-d H:i:s'); $endDate = \DateTime::createFromFormat('d-m-Y H:i:s', $endDate.' 23:59:59')->format('Y-m-d H:i:s'); $between = new Zend\Db\Sql\Predicate\Between('cre.'.$filter, $startDate, $endDate); $select->having ->nest ->equalTo('cre.paid', 0) ->and ->equalTo('cre.status', 'approved') ->and ->greaterThanOrEqualTo('cre.due_date', $currentDate) ->unnest ->or ->nest ->equalTo('cre.account_id', "acc.id") ->and ->equalTo('com.account_id', "acc.id") ->and ->greaterThanOrEqualTo('com.credit_max_amount', 'sum(cre.amount)') ->and ->equalTo('cre.paid', 0) ->and ->equalTo('cre.status', 'approved') ->unnest; 之后,生成的查询在我的phpmyadmin中成功运行。

但是当我实际运行代码时,错误显示,

  

无法使用sql生成语句:SELECT COUNT(1)AS $select->getSqlString(); FROM(SELECT Ccom AS name,{{1} }。com_name AS creamountcre_amount AS crestatuscre_status AS crepaidcre_paid AS crecreated_oncre_created_on AS creapproval_datecre_approval_date AS {{ 1}},ufirst_name AS u_first_name,CONCAT(u.first_name,&#34;&#34;,u.last_name)AS u,{{ 1}}。last_name AS u_last_nameapproved_bycre AS due_date FROM cre_due_date AS cre INNER JOIN {{1 } id ON cre_idcredit = crecompany LEFT JOIN com AS cre ON {{1} }。account_id = comaccount_id LEFT JOIN user AS u ON creapproved_by = uid WHERE accountacc BETWEEN?AND?HAVING(creaccount_id =?AND accid = ?AND crecreated_on&gt; =?)或(crepaid =?AND crestatus =?AND {{ 1}}。cre&gt; =?AND due_datecre =?AND account_idcom =?))AS account_id < / p>

有什么问题?我哪里错了?

0 个答案:

没有答案