我如何在Doctrine中实现它?
SELECT
(SELECT count(*)
FROM article
JOIN comments ON article.id = comments.article_id
WHERE
date(article.created) = '2015-02-06'
AND
article.id = 1) as a,
(SELECT count(*)
FROM article
JOIN comments ON article.id = comments.article_id
WHERE
date(article.created) = '2015-02-05'
AND
article.id = 1) as b
FROM article
GROUP BY article.id
LIMIT 1
这是我到目前为止所尝试的
public function createMyQuery($cdate, $aid){
$parameters = array(
'cdate' => $cdate,
'aid' => $aid,
);
$q = $this->getEntityManager()->createQueryBuilder()
->select(' ')
->addSelect('count(a.id)')
->from('ITJariSocialNetworkBundle:Article', 'a')
->where('article.created', ':cdate'))
->andWhere('article.id = :aid')
setParameters->($parameters)
;
return $q->getQuery();
}
//then i am looping on the calling of the function as following:
for($i=0; $i<7; $i++){
$postDate = date('Y-m-d',strtotime("-" .$i."days"));
$query = $this->createMyQuery(postDate, $aid);
}
$query->execute();
期望得到所有子查询的计数 但是我得到了异常错误结果 我的理由是我以错误的方式进行查询