我有以下SQL:如何按数字顺序对字母数字SQL Server NVARCHAR列进行排序?
SELECT fldTitle
FROM tblTrafficAlerts
ORDER BY fldTitle
它返回下列顺序的结果(从NVARCHAR
列):
A1M northbound within J17 Congestion
M1 J19 southbound exit Congestion
M1 southbound between J2 and J1 Congestion
M23 northbound between J8 and J7 Congestion
M25 anti-clockwise between J13 and J12 Congestion
M25 clockwise between J8 and J9 Broken down vehicle
M3 eastbound at the Fleet services between J5 and J4A Congestion
M4 J19 westbound exit Congestion
你会看到M23和M25是在M3以上所列和M4行,这看起来并不令人满意,而且如果扫描更长的结果列表,您不希望按照此顺序读取它们。
所以我想按字母顺序排序,然后数值结果,看起来像:
A1M northbound within J17 Congestion
M1 J19 southbound exit Congestion
M1 southbound between J2 and J1 Congestion
M3 eastbound at the Fleet services between J5 and J4A Congestion
M4 J19 westbound exit Congestion
M23 northbound between J8 and J7 Congestion
M25 anti-clockwise between J13 and J12 Congestion
M25 clockwise between J8 and J9 Broken down vehicle
因此M3和M4出现上述M23和M25。
标签DBMS。 (答案可能取决于使用的产品。) – jarlh
Microsoft SQL Server 2008 - 感谢您的标签编辑建议! – Rich
@JaydipJ该运营商尚未表示未按预期工作。他问的是如何排序与默认 –