Sybase 中的 ORDER BY desc

ORDER BY desc in Sybase

我有一个 table 有:

nb  | label 
60  | from 2 and less
25  | from 3 to 16
15  | from 17 to 100

我尝试获取降序,所以我使用查询:

select * from table order by label desc; 

但我没有得到正确的顺序,相反我有以下内容:

[ { nb: 25, label: 'from 3 to 16' },
  { nb: 60, label: 'from 2 and less' },
  { nb: 15, label: 'from 17 to 100' } ]

它是否将 17 视为 1?我怎样才能得到正确的顺序?

感谢您的帮助

这很痛苦。最简单的是如果您有另一列具有相同的顺序。但假设第二个单词是一个不以 0 开头的整数,第一个单词是 "from":

order by patindex('%[0-9] %', label) desc,
         left(label, patindex('%[0-9] %', label)) desc

这实际上是找到第一个数字的长度,并将其用于 order by 中的第一个键。然后它按第一个数字排序。

为了快速修复,只需将其更改为:

                     ...from 03 to 16' },
      { nb: 60, label: 'from 02 and less' },
      { nb: 15, label: 'from 17 to 100' } ]

或额外的 space 而不是零:

                     ...from  3 to 16' },
      { nb: 60, label: 'from  2 and less' },
      { nb: 15, label: 'from 17 to 100' } ]

两者都应该按您想要的方式排序。