我试图用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(SELECTC
。com
ASname
,{{1} }。com_name
AScre
,amount
。cre_amount
AScre
,status
。cre_status
AScre
,paid
。cre_paid
AScre
,created_on
。cre_created_on
AScre
,approval_date
。cre_approval_date
AS {{ 1}},u
。first_name
ASu_first_name
,CONCAT(u.first_name,&#34;&#34;,u.last_name)ASu
,{{ 1}}。last_name
ASu_last_name
,approved_by
。cre
ASdue_date
FROMcre_due_date
AScre
INNER JOIN {{1 }id
ONcre_id
。credit
=cre
。company
LEFT JOINcom
AScre
ON {{1} }。account_id
=com
。account_id
LEFT JOINuser
ASu
ONcre
。approved_by
=u
。id
WHEREaccount
。acc
BETWEEN?AND?HAVING(cre
。account_id
=?ANDacc
。id
= ?ANDcre
。created_on
&gt; =?)或(cre
。paid
=?ANDcre
。status
=?AND {{ 1}}。cre
&gt; =?ANDdue_date
。cre
=?ANDaccount_id
。com
=?))ASaccount_id
< / p>
有什么问题?我哪里错了?