1

Column是一个字符串,里面的数据可以是

10
2
3
3.1
3.2
a10
a11
1
a12.2
a12.3

希望结果返回为:

1
2
3
3.1
3.2
10
a10
a11
a12.2
a12.3

这将是带有 MSACCESS Web 数据库的 ASP/VBScript(Provider=Microsoft.Jet.OLEDB.4.0;Data Source)

4

3 回答 3

1

MS Access怎么样:

SELECT IIf(IsNumeric(Left([fld],1)),0,Left([fld],1)) AS Expr1, 
  Val(IIf(IsNumeric(Left([fld],1)),[fld],Mid([fld],2))) AS Expr2, Fld
FROM Table
ORDER BY IIf(IsNumeric(Left([fld],1)),0,Left([fld],1)), 
  Val(IIf(IsNumeric(Left([fld],1)),[fld],Mid([fld],2)));
于 2012-09-24T20:05:44.703 回答
1

您可以尝试先按字段长度排序,然后按字段值排序。像这样的东西:

SELECT FIELD FROM TABLE ORDER BY LEN(FIELD), FIELD

它在这里工作,看看是否有另一个测试用例阻止它。

于 2012-09-24T20:14:03.370 回答
1

如果非数字字符串始终以示例中的单个字母开头,则可以 ORDER BY 三列表达式。

SELECT DISTINCT
    IIf(IsNumeric(the_column) = True, 0, 1) AS order_by1,
    IIf(IsNumeric(the_column) = True, '', Left(the_column,1)) AS order_by2,
    IIf(IsNumeric(the_column) = True,
        Val(the_column), Val(Mid(the_column,2))) AS order_by3,
    the_column
FROM YourTable
ORDER BY 1, 2, 3;

如果您不希望结果集中出现这些 order_byX 字段,请将它们移到 ORDER BY 子句中。

SELECT DISTINCT
    the_column
FROM YourTable
ORDER BY
    IIf(IsNumeric(the_column) = True, 0, 1),
    IIf(IsNumeric(the_column) = True, '', Left(the_column,1)),
    IIf(IsNumeric(the_column) = True,
        Val(the_column), Val(Mid(the_column,2)));
于 2012-09-24T21:04:56.520 回答