所以,如果我有结果
11 The street
9 The street
59 The street
常规ORDER BY ASC
执行此操作
11 The street
59 The street
9 The street
如何按ASC
订购,并将数字计算为
9 The street
11 The street
59 The street
答案 0 :(得分:2)
请尝试:
select *
From tbl
order by cast(Left(Col, PatIndex('%[^0-9]%', Col)) as int)
对于MySql,请尝试:
select *
From tbl
order by convert(SUBSTRING_INDEX(Col, ' ', 1), UNSIGNED INTEGER)
答案 1 :(得分:0)
另一种解决方案(有点简单);只是按照您的示例数据进行操作,并假设您的所有数据字符串都有The Street
个共同点。另外,TechDo所建议的应该是我将要去的那个(对于通用解决方案)
select * from tbl
order by
cast(
(substring(col,0,charindex('The street',col))) as int)