我有一个查询,它将显示具有重复值或超过1个值的列

select date_created,loan_id,count(1) as cnt
from collections
group by date_created,loan_id
having count(1)>1;

我想把它转换成条令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"

最佳答案

我希望问题出在伯爵身上。尝试以下操作

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();
}

关于mysql - 原则1选择具有重复值的列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28163673/

10-13 00:49