SELECT * FROM users INNER JOIN ratings ON ratings.rateable=users.id ORDER BY SUM(ratings.rating)/COUNT(ratings.rating)