I have a Rating table in my SQL database and I would like to return the
row containing the highest average rating where the picture_id for that
row is a certain value. I could do this by SQL but I'd like to use the
Ruby functions if it's possible.
I can get the maximum value of rating like this:
@rating = Rating.maximum(:rating, :conditions => ['picture_id = ?',
which works great but only returns the maximum value for the column
"rating" when I want the whole row of values for the record with the
The SQL would be something like this:
SELECT user_id, picture_id, max(rating) FROM ratings WHERE picture_id =
? GROUP BY user_id, picture_id', @picture_id]
I've not tested that but you get the idea...
So is there anyway of running the above SQL using a ruby function ?
Thanks for any help