0

运行我的sql查询后,结果是

1.12.1
1.12.2
1.12.3
1.12.4
1.12.5
1.12.6
1.12.7
1.12.8
1.12.9
1.12.10
1.12.11
1.12.2a 

但我想要这个结果(“2”之后的“2a”)

1.12.1
1.12.2
1.12.2a <-- This one must be here, not at the end of the result set
1.12.3
1.12.4
1.12.5
1.12.6
1.12.7
1.12.8
1.12.9
1.12.10
1.12.11

什么样的sql查询可以做到这一点?

这是我的查询...我使用 SQL Server 2012

sResultSqlBuilder.Append("ORDER BY {0} {1}")

如果 sortExpression = " " 那么

sResultSql = String.Format(sResultSql, "Right('0000000000' + FirstNumber, 10),Right('0000000000' + SecondNumber, 10),Right('0000000000' + ThirdNumbersAndLetter, 10) ", " ")

4

1 回答 1

0

请尝试,它适用于 MS-Sql 服务器:

SELECT VersionNo, 
Cast(PARSENAME(VersionNo, 3)as int) as Num1, 
cast(PARSENAME(VersionNo, 2) as int) as Num2, 
cast(PARSENAME(VersionNo, 1) as nvarchar(2)) as Num3 
FROM 
(
    select '1.12.2' as VersionNo union
    select '1.12.3' as VersionNo union
    select '1.12.2a' as VersionNo union
    select '1.12.1' as VersionNo union
    select '1.12.4' as VersionNo
)x
Order by Num1, Num2, num3
于 2013-03-22T09:44:49.200 回答