mysql - Find avg of rating for each item -
i have table feilds : file_id, rating, user_id
there 1 rating per user_id, there many rating (in scale of 0-5) single file_id.
i want find avg of ratings every file_id , display 5 file_id highest avg rating.
actually sql query looks like:
select m.server_domain, m.original_name, m.type, m.title, m.views, m.description, m.hash, avg(mr.rating_scale5) avg_rating_scale5 c7_media m, c7_storage s, c7_media_ratings mr s.public=1 , m.storage_hash = s.hash , m.hash = mr.media_hash group mr.media_hash
how should this?
zeeshan
group file_id
, order average. cut off records fall below top 5.
select file_id, avg(rating) avg_rating table group file_id order avg_rating desc limit 5
Comments
Post a Comment