MYSQL WHERE子句不适用于生成的字段

时间:2015-03-12 20:09:52

标签: php mysql where-clause

大家好,由于某种原因,WHERE rating = 1条款在这种情况下不起作用。我认为这可能与在为生成评级生成字段执行内部语句之前构造的外部sql语句有关,因为它可以与其他字段一起使用。

SELECT 
    property.id as propertyid, 
    property.main_image as mainimageid, 
    property.number as number, 
    property.address as address, 
    property.number as number, 
    property.area as area, 
    image.id as imageid, 
    CAST((SELECT sum(review.rating) / COUNT(*) / 20 as innerrating 
          FROM 
              review 
          WHERE 
              review.propertyid = property.id) AS decimal(3,2)) as rating
    FROM 
        property 
    LEFT JOIN 
        propertyimage ON propertyimage.propertyid = property.id 
    LEFT JOIN 
        image on image.id = propertyimage.imageid 
    LEFT JOIN 
        review on review.propertyid = property.id 
    WHERE 
        rating = 1 
    GROUP BY propertyid

任何帮助将不胜感激:)

0 个答案:

没有答案