dqbn76906 2013-05-11 09:54
浏览 79
已采纳

基于2个字段在SQL中排序

I'm making a way to compare players, basically - hiscores. A problem I have is this: I need to order based on two variables. Currently I'm ordering by the total level, and if there's two or more players with the same total level, I want to order it by their total xp.

Example: I have the query

SELECT * FROM overall ORDER BY `total_level` DESC LIMIT 30

And it returns this http://gyazo.com/73698236977bbe2b94f8079d769b81a5.png

This is not good because since they have the same Total Level, I need it to order by their total xp to show that one member is better than the other.

  • 写回答

1条回答 默认 最新

  • duanbanfei2875 2013-05-11 09:57
    关注

    What about giving both columns to order directly in your query?

    SELECT * FROM overall ORDER BY `total_level` DESC, `total_xp` DESC LIMIT 30
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM