![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 ;-) |
#3
| |||
| |||
|
#4
| |||
| |||
|
#5
| |||
| |||
|
|
There are several ways I can think of to do this but here's one. Two queries. One returns the top 40%, another less than 5 votes. Union. Wrap them with another query and use distinct to de-dupe. |
#6
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |