我的数据库查询有问题。我需要设置最大结果,但是当我这样做时,我没有得到我期望的结果。 (例如,当我有2"主题标签"减少一个) 这是代码:
$r = $this->createQueryBuilder("q")
->select("q AS image, sb, hs")
->addSelect("c, SUM(CASE WHEN (c.likeCount!=false) THEN c.likeCount ELSE 0 END) AS likes")
->addSelect("cm, COUNT(cm) AS comments")
->addSelect("u, SUM(CASE WHEN (c.user=:user) THEN c.likeCount ELSE 0 END) AS userLiked")
->leftJoin("q.siteBox","sb")
->leftJoin("q.imageLikes","c")
->leftJoin("q.hashtags","hs")
->leftJoin("q.comments","cm")
->setMaxResults(4)
->leftJoin("c.user","u")
->setParameter("user",$user)
->groupBy("hs.id,q.id")
->orderBy("q.date","DESC")
;
抱歉我的英语不好,但我想大家都会理解。