Hi guys for some reason the WHERE rating = 1 clause is not working in this case. I think it might be to do with the outer sql statement being constructed prior to the inner statement being executed for the as rating generated field, as it works fine with the other fields.
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
any help would be greatly appreciated :)