我有一个查询,它会显示重复或超过1个值的列。我可以使用sql显示它
select date_created,loan_id,count(1) as cnt
from collections
group by date_created,loan_id
having count(1)>1;
我希望转换为Doctrine 1查询,我试过
public function getDuplicateDatePayment() {
$q = $this->createQuery('c')
->select('c.date_created,c.loan_id,c.count(1) as cnt')
->groupBy('c.date_created','c.loan_id')
->having('c.count(1) > 1');
return $q->execute();
}
但它只返回错误。关于如何正确地将所述工作sql转换为doctrine 1查询的任何想法?
SQLSTATE[42000]: Syntax error or access violation: 1630 FUNCTION c.count does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual. Failing Query: "SELECT c.id AS c__id, c.date_created AS c__date_created, c.loan_id AS c__loan_id, c.count(1) AS c__0, c.count(1) AS c__0 FROM collections c GROUP BY c.date_created HAVING c.count(1) > 1"
答案 0 :(得分:1)
我希望这个问题可能会有问题。请尝试以下
public function getDuplicateDatePayment() {
$q = $this->createQuery('c')
->select('c.date_created,c.loan_id,count(c.1) as cnt')
->groupBy('c.date_created','c.loan_id')
->having('c.count(1) > 1');
return $q->execute();
}