symfony2中的SQL查询异常 - 左外连接

时间:2011-12-30 23:14:51

标签: sql join symfony

我正在尝试获取图库中的图像列表,评级总和和选民数量。我做sql查询:

    SELECT img.id, img.title, img.image, img.thumb, img.link, img.published, 
        rating.sum, rating.voters
    FROM AcmeMainBundle:Category cat, AcmeMainBundle:User usr, AcmeMainBundle:Image img                
    LEFT OUTER JOIN                        
    (
      SELECT SUM(r.rating) as sum, COUNT(r.rating) as voters, r.image
      FROM AcmeMainBundle:ImgRating r
    ) AS rating ON rating.image = img.id
    WHERE usr.username = :user AND cat.user = usr.id AND 
       cat.id = :category AND img.category = cat.id
    ORDER BY img.order ASC, img.id DESC

但我收到例外:

    [Semantical Error] line 0, col 253 near 'SELECT SUM(r.rating)': Error:         
    Identification Variable ( used in join path expression but was not defined before.

1 个答案:

答案 0 :(得分:1)

嗯......我相信在FROM / JOIN中没有得到支持。

如果我是你,我会尝试使用名为“评级”的子选项进行观察。如果这不起作用,您应该以不同的方式重新构造查询=)。

如果你不能发表评论,我会帮忙。