dongyi5070 2014-06-21 08:39
浏览 8
已采纳

MySQL ORDER BY不是最常见的

Hello i have this table which contains users and the amount of points they have and i want to display the table starting from the users with the highest points but when i try the code below what it does is it shows the most common amount of points.

SELECT * FROM users ORDER BY points ASC

But instead of

User | Points
Bob    20
Jon    16
Abu    16
Eli    15

It does

User | Points
Jon    16
Abu    16
Bob    20
Eli    15

See shouldn't 20 be on top? it does it by most common points any help I am new to PHP

EDIT: Thanks to Hanky 웃 Panky i realized what i needed to do

ORDER BY CAST(points AS unsigned) DESC 

Is the correct way.

  • 写回答

3条回答 默认 最新

  • dounao2829 2014-06-21 08:42
    关注

    Your Points field must be a String to be interpreted that way. Cast it as a number( if you cant change data type to become a number permanently) and you are good.

    SELECT * FROM users ORDER BY CAST(points AS unsigned) ASC
    

    And for a Descending order, use DESC instead of ASC

    Fiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记