doujing1858
2016-04-13 15:30
浏览 48
已采纳

Doctrine QueryBuilder HAVING表达式

OK, so I'm rewriting some code, using Doctrine ORM (2.5).

The old code creates a query that has something like this:

SELECT * FROM couples INNER JOIN individuals ON (couples.id = individuals.couple_id)
GROUP BY couples.id
HAVING SUM(individuals.date_of_birth <= '1976-01-01') > 0

I have no clue how to implement this best using the Doctrine QueryBuilder. This is a very simplified example, the real query is much longer and has a few HAVING clauses, all of which use SUM(some_condition) > 0 to ensure that only Couples that contain a matching Individual will be retrieved.

I can add having clauses in Doctrine using $queryBuilder->having(), but I cannot do so using the SUM() function. Any ideas?

图片转代码服务由CSDN问答提供 功能建议

好的,所以我正在使用Doctrine ORM(2.5)重写一些代码。 \ n

旧代码创建一个具有以下内容的查询:

  SELECT * FROM将INNER JOIN个人联系起来(couples.id = persons.couple_id)
 
GROUP BY  couples.id 
HAVING SUM(persons.date_of_birth&lt; ='1976-01-01')&gt;  0 
   
 
 

我不知道如何使用Doctrine QueryBuilder实现这一目标。 这是一个非常简化的示例,真正的查询更长,并且有一些HAVING子句,所有这些都使用 SUM(some_condition)&gt; 0 以确保只检索包含匹配个体的Couples。

我可以使用 $ queryBuilder-&gt; having()<在Doctrine中添加having子句 / code>,但我不能使用 SUM()函数。 有什么想法吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题