View Single Post

   
  #1 (permalink)  
Old 02-29-2008, 07:28 AM
andreas.muller@gmail.com
 
Posts: n/a
Default SQL query - highest rated or least voted items

Hello everyone,

I'm trying to solve this problem but can't seem to figure out how to
start. I would like to create a rating system where people can vote
(1-5 stars) on randomly displayed items. The randomly displayed items
should either have very high ratings OR a very low number of ratings.
For example, only return items in the top 20th percentile *OR* items
with fewer than 5 votes.

The question is, how would I write an SQL query to return such a
result? Is it even possible? Should this be handled by my application
rather than the database?

For simplicity, let's assume I have the following table:

tbl_items
-----------------
item_id
item_name
avg_rating
num_votes
-----------------

Any help or pointers in the right direction would be greatly
appreciated. My apologies in advance if the solution is obvious and I
am clearly missing the point ;-)

Reply With Quote