-2

I have a table that looks something like this, where name is the person's name, and the votes is how many people have rated this person, and the rating_percent is just basically the rating percent itself where 5.0 is the highest. Now my question is, what is the best way to sort them up depending on the number of their votes and rating_percent. And can you also give me a sample code.

|   id   |  name    |   votes   |   rating_percent  |
|   1    |  George  |   12      |       4.5         |
|   2    |  Pamela  |   1       |       5.0         |
|   3    |  Britney |   22      |       3.2         |
|   4    |  Lucas   |   43      |       1.2         |
|   5    |  Bobby   |   54      |       2.4         |
peterm
  • 91,357
  • 15
  • 148
  • 157
user2310422
  • 555
  • 3
  • 9
  • 22
  • 1
    SELECT * FROM `table` ORDER BY `votes`, `rating_percent` ?? – sectus Jul 01 '13 at 04:38
  • `SELECT * FROM table ORDER BY votes DESC, rating_percent DESC`, first order by votes (from most to least = descending), then (when same votes) order by descending rating_percent...? – xerx593 Feb 15 '19 at 21:19

3 Answers3

0

Th query will be

SELECT * FROM table_name
ORDER BY votes desc, rating_percent desc
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
0

You can sort like this to get sorting results by two fields.

 Select * from tableName order by votes desc,rating_percent desc
Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
0

mostly like this

SELECT * FROM table_name ORDER BY name DESC, votes  DESC
Rajeev Ranjan
  • 4,152
  • 3
  • 28
  • 41