按名称排序不按预期工作 - MySQL

时间:2014-07-07 09:11:35

标签: mysql sql-order-by

我有以下简单查询:

SELECT * FROM grade order by GRADENAME

输出:

enter image description here

这是一个主要在用户体验部分的问题,因为他收到<select></select>元素的成绩,如上面的列表所示。我有没有办法让他们从1A开始一直显示11D?有可能这样做吗?

修改

应用SELECT * FROM grade order by BIN(GRADENAME);

结果:

enter image description here

3 个答案:

答案 0 :(得分:1)

试试这个

SELECT * FROM grade order by BIN(GRADENAME);

答案 1 :(得分:1)

可能是这样的

SELECT * FROM grade 
Order By Cast(SubString(GRADENAME,1,Length(GRADENAME) -1 As Int),Right(GRADENAME,1)

或者

SELECT * FROM grade 
Order By lpad(GRADENAME, 10, 0)

答案 2 :(得分:0)

试试这个

SELECT GRADEID, 
       GRADENAME 
FROM   GRADE 
GROUP  BY GRADENAME 
ORDER  BY 2;