I have 2 tables, one is supplier and one is supplier_feedback - how can I calculate the average rating for each supplier? I currently have this:
SELECT s.premium, s.supplier_id, s.name, s.phone, s.website,
s.price_low, s.price_high, s.address1, s.address2, s.town,
s.county, s.postcode,
(SUM( f.rating ) / ( COUNT( f.rating ) -1 )) AS rate,
GROUP_CONCAT( REPLACE( t.name, ' ', ',' ) SEPARATOR ',' ) AS tags
FROM suppliers AS s
JOIN suppliers_to_tags AS st ON st.supplier_id = s.supplier_id
JOIN supplier_tags AS t ON t.tag_id = st.tag_id
JOIN supplier_feedback AS f ON s.supplier_id = f.supplier_id
GROUP BY s.supplier_id
HAVING tags LIKE '%HI%'
ORDER BY s.premium DESC
LIMIT 0 , 30
But I get very strange results, which definitely aren't correct.
The supplier_feedback table will have many records, but the first record must be discounted for various reasons.