在Mysql中排序结果

时间:2013-07-01 04:35:23

标签: mysql sql sorting

我有一个看起来像这样的表,其中name是人的名字,而投票是有多少人评价了这个人,而rating_percent基本上是5.0本身最高的评级百分比。现在我的问题是,根据他们的投票数量和rating_percent对它们进行排序的最佳方法是什么。你能不能给我一个示例代码。

|   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         |

3 个答案:

答案 0 :(得分:0)

查询将是

SELECT * FROM table_name
ORDER BY votes desc, rating_percent desc

答案 1 :(得分:0)

您可以这样排序,以便通过两个字段获得排序结果。

 Select * from tableName order by votes desc,rating_percent desc

答案 2 :(得分:0)

大多喜欢这个

SELECT * FROM table_name ORDER BY name DESC, votes  DESC