我目前有一个简单的MySQL select,在一个名为postcodes的列上有一个order by。这些邮政编码是英国。
它当前的输出顺序是:SE1, SW1, SE10, SE11, SE2, SW2, SE3。我知道使用ABS()可以纠正数字排序,但我不确定在这种情况下该如何做,因为既有字母也有数字。
我想按以下顺序显示它们:
SE1, SE2, SE3 SE10, SE11, SW1, SW2
谢谢你的帮助。
发布于 2012-07-07 18:04:14
您可以向表中添加一些额外的列,以在其中包含代码片段,并通过使用第三列进行排序来返回顺序。例如:
PostCodeTable
|---------------------------------------------|
|postCode| codePart1 | codePart2 | codePart3 |
|char() | char() | int() | whatever() |
|---------------------------------------------|
| SE1 | SE | 1 | |
| SW1 | SW | 10 | |
| SE10 | SE | 10 | |
| SE11 | SE | 11 | |
| SE2 | SE | 2 | |
| SW2 | SW | 2 | |
| SE3 | SE | 3 | |
|---------------------------------------------|您的查询可能是:
Select
postCode
from
PostCodeTable
order by
codePart1,
codePart2
// etc etc as needed.https://stackoverflow.com/questions/9913140
复制相似问题