在我的表中有两个文件,一个是id,另一个是strNum。我想像这样订购 strNum
One
Two
Three
我的表格数据
id strNum
------ ------------
1 Two
2 One
3 Five
4 Nine
我想在不添加任何额外字段的情况下获得输出。我怎样才能像这样订购
One
Two
Three
Four
Five
最佳答案
你可以使用Case
:
select strNum
from A
order by case when strNum='one' then 1
when strNum='two' then 2
when strNum='three' then 3
when strNum='four' then 4
when strNum='five' then 5
when strNum='six' then 6
when strNum='seven' then 7
when strNum='eight' then 8
when strNum='nine' then 9
when strNum='ten' then 10 end
您没有提到您使用的是哪个数据库。这是 PostgreSQL 版本。 参见 SQLFiddle
关于mysql - SQL按字符串顺序排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32293636/