MySQL sql从高到低排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20008638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sql order by from highest to lowest value
提问by ntm
SELECT * FROM highscore ORDER BY score
This code always sorts my values for lowest to highest but I want them from the highest to the lowest.
这段代码总是将我的值从最低到最高排序,但我希望它们从最高到最低。
Actually I have two sets of data in my table and I always get:
实际上我的表中有两组数据,我总是得到:
0
235235
But I need it to be like this:
但我需要它是这样的:
235235
0
I have already tried:
我已经尝试过:
SELECT * FROM highscore ORDER BY CAST(score AS int)
But that gave me a syntax-error:
但这给了我一个语法错误:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT)' at line 1"
“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的 'INT)' 附近使用的正确语法”
In my table score is set as int(100)
.
在我的表格中,分数设置为int(100)
.
Does anybody have a solution how I could sort them like that? There will never be negative or non-int values.
有没有人有解决方案,我可以这样对它们进行排序?永远不会有负值或非整数值。
回答by Paul92
You have to use
你必须使用
SELECT * FROM highscore ORDER BY score DESC
There also exists
还有存在
SELECT * FROM highscore ORDER BY score ASC
, but this is the default behaviour.
,但这是默认行为。