简体   繁体   中英

The most logical way to order up-votes and down-votes and how to do it

In my database I have a number of up-votes and a number of down-votes for each row in the table and they represent some kind of calification for that item.

When displaying all items in a table, what would be the most logical way to order those according to the values of the votes? I have thought of:

  • Number of positive votes (descendent, obviously)
  • Number of positive votes - number of negative votes
  • Relation between number of positive votes and negative votes

Which would make more sense?

Also, for the last one, how could I make the SQL query? How do I treat the division by 0 case here? If I chose this option, depending on the way I'm going to treat the 0 (I don't know how to do that in the order by clause), if it were the one closest to the reality (the result would be infinity), then an item with 2 up-votes and 0 down-votes would be displayed with highest priority that an item with 1000 up-votes and 3 down-votes. Doesn't this seem "unfair" for this last item?

Any suggestions?

It highly depends on your application but I found that up-voting is easier than down-voting... in general. So maybe you should take into consideration adding greater weight to the down votes. Going to the point maybe consider using third attribute kind of voting_counts_coefficient and use it without putting logic to the query. Referential integrity you can achieve by using some triggers or procedures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM