douyue2313 2014-07-28 15:44
浏览 159
已采纳

按顺序排序,如果有些相同,则按SQL中的其他顺序排序

Hi I am looking to sort a table of players on my site.

For instance people are predicting scores, I have everything set and working but was wondering if its possible to set an order and if the order has 2 the same, then order them 2 by something else.

For instance here is the query I am using just to order.

"SELECT * FROM league ORDER BY points DESC";

Now if a user has the same points I would then like to go for goal difference, if that is the same go for goals scored, and if that is the same finally go for persons name.

Is this possible in sql or is this a php algorithm I need?

Thanks

  • 写回答

2条回答 默认 最新

  • doujiayuan8415 2014-07-28 15:45
    关注

    You just need to order on multiple columns.

    SELECT *
    FROM league
    ORDER BY points DESC, goalDiff DESC, goalsScored DESC, playerName
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题