1

我想用 Doctrine 计算子选择返回的行数。我的子选择是:

SELECT e FROM \comments\Entities\Event e 
WHERE e.type = 'addComment'
HAVING TIMESTAMPDIFF(MINUTE, e.commentedOnPublished, e.created) < 60)

在 SQL 中,我将通过以下方式实现预期的结果:

SELECT COUNT(*) FROM (
    SELECT e.* FROM square_events as e 
    WHERE e.type = 'addComment' 
    HAVING TIMESTAMPDIFF(minute, e.commentedOnPublished, e.created) < 60
) temp

有谁知道如何用 Doctrine 实现这一点?

4

2 回答 2

2

我确定我已经尝试过这个和一千个其他解决方案,无论如何,在我们的一个系统人员指出我是个白痴之后,这就是我最终得到的结果!

SELECT COUNT(e) as eventCount FROM comments\Entities\Event e 
WHERE e.type = 'addComment'
AND TIMESTAMPDIFF(MINUTE, e.commentedOnPublished, e.created) < 60

那些日子中的一天...

于 2012-05-09T10:23:31.013 回答
1

我看不出想要子选择的原因。以下应该可以正常工作:

$query = $em->createQuery("
    SELECT COUNT(e.id) FROM \comments\Entities\Event e 
    WHERE e.type = 'addComment'
    HAVING TIMESTAMPDIFF(MINUTE, e.commentedOnPublished, e.created) < 60)"
);

$count = $query->getSingleScalarResult();
于 2012-05-08T20:28:36.303 回答