mysql - Doctrine 1 选择具有重复值的列

标签 mysql sql doctrine-1.2

我有一个查询将显示具有重复值或超过 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"

最佳答案

我希望问题出在计数上。尝试以下操作

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 - Doctrine 1 选择具有重复值的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28163673/

相关文章:

insert - 如何在 DQL 中进行插入查询

php - Doctrine 1.2 控制流函数 "IF"

MySQL 调谐器 : High ratio of temporary tables created on disk - Website Slow response

sql - 判断一个表是否有一些唯一的列

sql - 建表查询

php - mysqli_insert_id 的问题

mysql - 学说限制打破了我的查询?

php - PDO SQLSRV 和 PDO MySQL 在获取 int 或 float 时返回字符串

php (PDO) 将查找表中的行转换为简单数组的简单方法

php - 递归列表函数