按点排序,但如果在MySQL中相同的顺序

时间:2014-03-11 14:29:34

标签: mysql sql sql-order-by

我现在按点排序我的表格结果。 但它需要按点排序,但如果这与按差异排序相同。

现在就是这样:

... ORDER BY Points DESC";

但我希望有这样的东西:

... ORDER BY Points (if two have the same amount) Than ORDER BY Goal Difference

希望你能帮忙

3 个答案:

答案 0 :(得分:0)

如果您在问题中包含完整查询,这将有所帮助。 order by子句可以接受多个参数。当你说出问题时,答案就是:

order by Points desc, GoalDifference

您可能想要一个表达式:

order by Points, t1.Goals - t2.Goals

order by中也允许使用这些内容。

答案 1 :(得分:0)

当您按两列排序时,它会占用第一列,而第一列的值相等,它将按第二列排序,因此它只需要执行您需要的操作。

您可以使用:order by Points, GoalDifference

或者你甚至可以用不同的顺序来做:

order by Points DESC, GoalDifference

order by Points, GoalDifference DESC

您始终可以参考MYSQL文档:

https://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html

此链接来自旧版本,但其他版本没有更改。

答案 2 :(得分:0)

正确答案是: 谢谢!

ORDER BY Points DESC, Goal Difference DESC

这对我有用

相关问题